All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.swt.widgets.Table Maven / Gradle / Ivy

Go to download

SWT is an open source widget toolkit for Java designed to provide efficient, portable access to the user-interface facilities of the operating systems on which it is implemented.

The newest version!
/*******************************************************************************
 * Copyright (c) 2000, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.widgets;


//import java.util.*;

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.win32.*;

/** 
 * Instances of this class implement a selectable user interface
 * object that displays a list of images and strings and issues
 * notification when selected.
 * 

* The item children that may be added to instances of this class * must be of type TableItem. *

* Style VIRTUAL is used to create a Table whose * TableItems are to be populated by the client on an on-demand basis * instead of up-front. This can provide significant performance improvements for * tables that are very large or for which TableItem population is * expensive (for example, retrieving values from an external source). *

* Here is an example of using a Table with style VIRTUAL: *

 *  final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
 *  table.setItemCount (1000000);
 *  table.addListener (SWT.SetData, new Listener () {
 *      public void handleEvent (Event event) {
 *          TableItem item = (TableItem) event.item;
 *          int index = table.indexOf (item);
 *          item.setText ("Item " + index);
 *          System.out.println (item.getText ());
 *      }
 *  }); 
 * 
*

* Note that although this class is a subclass of Composite, * it does not normally make sense to add Control children to * it, or set a layout on it, unless implementing something like a cell * editor. *

*

*
Styles:
*
SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL, NO_SCROLL
*
Events:
*
Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem
*
*

* Note: Only one of the styles SINGLE, and MULTI may be specified. *

* IMPORTANT: This class is not intended to be subclassed. *

* * @see Table, TableItem, TableColumn snippets * @see SWT Example: ControlExample * @see Sample code and further information * @noextend This class is not intended to be subclassed by clients. */ public class Table extends Composite { TableItem [] items; int [] keys; TableColumn [] columns; int columnCount, customCount, keyCount; ImageList imageList, headerImageList; TableItem currentItem; TableColumn sortColumn; RECT focusRect; int /*long*/ headerToolTipHandle; boolean ignoreCustomDraw, ignoreDrawForeground, ignoreDrawBackground, ignoreDrawFocus, ignoreDrawSelection, ignoreDrawHot; boolean customDraw, dragStarted, explorerTheme, firstColumnImage, fixScrollWidth, tipRequested, wasSelected, wasResized, painted; boolean ignoreActivate, ignoreSelect, ignoreShrink, ignoreResize, ignoreColumnMove, ignoreColumnResize, fullRowSelect; int itemHeight, lastIndexOf, lastWidth, sortDirection, resizeCount, selectionForeground, hotIndex; static /*final*/ int /*long*/ HeaderProc; static final int INSET = 4; static final int GRID_WIDTH = 1; static final int SORT_WIDTH = 10; static final int HEADER_MARGIN = 12; static final int HEADER_EXTRA = 3; static final int VISTA_EXTRA = 2; static final int EXPLORER_EXTRA = 2; static final int H_SCROLL_LIMIT = 32; static final int V_SCROLL_LIMIT = 16; static final int DRAG_IMAGE_SIZE = 301; static final boolean EXPLORER_THEME = true; static boolean COMPRESS_ITEMS = true; static final int /*long*/ TableProc; static final TCHAR TableClass = new TCHAR (0, OS.WC_LISTVIEW, true); static { WNDCLASS lpWndClass = new WNDCLASS (); OS.GetClassInfo (0, TableClass, lpWndClass); TableProc = lpWndClass.lpfnWndProc; } /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. *

* The style value is either one of the style constants defined in * class SWT which is applicable to instances of this * class, or must be built by bitwise OR'ing together * (that is, using the int "|" operator) two or more * of those SWT style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. *

* * @param parent a composite control which will be the parent of the new instance (cannot be null) * @param style the style of control to construct * * @exception IllegalArgumentException
    *
  • ERROR_NULL_ARGUMENT - if the parent is null
  • *
* @exception SWTException
    *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  • *
  • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
  • *
* * @see SWT#SINGLE * @see SWT#MULTI * @see SWT#CHECK * @see SWT#FULL_SELECTION * @see SWT#HIDE_SELECTION * @see SWT#VIRTUAL * @see SWT#NO_SCROLL * @see Widget#checkSubclass * @see Widget#getStyle */ public Table (Composite parent, int style) { super (parent, checkStyle (style)); } void _addListener (int eventType, Listener listener) { super._addListener (eventType, listener); switch (eventType) { case SWT.MeasureItem: case SWT.EraseItem: case SWT.PaintItem: setCustomDraw (true); setBackgroundTransparent (true); if (OS.COMCTL32_MAJOR < 6) style |= SWT.DOUBLE_BUFFERED; if (OS.IsWinCE) OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_LABELTIP, 0); break; } } boolean _checkGrow (int count) { //TODO - code could be shared but it would mix keyed and non-keyed logic if (keys == null) { if (count == items.length) { /* * Grow the array faster when redraw is off or the * table is not visible. When the table is painted, * the items array is resized to be smaller to reduce * memory usage. */ boolean small = getDrawing () && OS.IsWindowVisible (handle); int length = small ? items.length + 4 : Math.max (4, items.length * 3 / 2); TableItem [] newItems = new TableItem [length]; System.arraycopy (items, 0, newItems, 0, items.length); items = newItems; } } else { //TODO - don't shrink when count is very small (ie. 2 or 4 elements)? //TODO - why? if setItemCount(1000000) is used after a shrink, then we won't compress //TODO - get rid of ignoreShrink? if (!ignoreShrink && keyCount > count / 2) { boolean small = getDrawing () && OS.IsWindowVisible (handle); int length = small ? count + 4 : Math.max (4, count * 3 / 2); TableItem [] newItems = new TableItem [length]; for (int i=0; i 4 && items.length - count > 3) { int length = Math.max (4, (count + 3) / 4 * 4); TableItem [] newItems = new TableItem [length]; System.arraycopy (items, 0, newItems, 0, count); items = newItems; } } } else { if (!ignoreShrink) { if (keys.length > 4 && keys.length - keyCount > 3) { int length = Math.max (4, (keyCount + 3) / 4 * 4); int [] newKeys = new int [length]; System.arraycopy (keys, 0, newKeys, 0, keyCount); keys = newKeys; TableItem [] newItems = new TableItem [length]; System.arraycopy (items, 0, newItems, 0, keyCount); items = newItems; } } } } void _clearItems () { items = null; keys = null; keyCount = 0; } TableItem _getItem (int index) { return _getItem (index, true); } //TODO - check senders who have count (watch methods that change the count) TableItem _getItem (int index, boolean create) { return _getItem (index, create, -1); } TableItem _getItem (int index, boolean create, int count) { //TODO - code could be shared but it would mix keyed and non-keyed logic if (keys == null) { if ((style & SWT.VIRTUAL) == 0 || !create) return items [index]; if (items [index] != null) return items [index]; return items [index] = new TableItem (this, SWT.NONE, -1, false); } else { if ((style & SWT.VIRTUAL) == 0 || !create) { if (keyCount == 0) return null; if (index > keys [keyCount - 1]) return null; } int keyIndex = binarySearch (keys, 0, keyCount, index); if ((style & SWT.VIRTUAL) == 0 || !create) { return keyIndex < 0 ? null : items [keyIndex]; } if (keyIndex < 0) { if (count == -1) { count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); } //TODO - _checkGrow() doesn't return a value, check keys == null instead if (_checkGrow (count)) { if (items [index] != null) return items [index]; return items [index] = new TableItem (this, SWT.NONE, -1, false); } keyIndex = -keyIndex - 1; if (keyIndex < keyCount) { System.arraycopy(keys, keyIndex, keys, keyIndex + 1, keyCount - keyIndex); System.arraycopy(items, keyIndex, items, keyIndex + 1, keyCount - keyIndex); } keyCount++; keys [keyIndex] = index; } else { if (items [keyIndex] != null) return items [keyIndex]; } return items [keyIndex] = new TableItem (this, SWT.NONE, -1, false); } } void _getItems (TableItem [] result, int count) { if (keys == null) { System.arraycopy (items, 0, result, 0, count); } else { /* NOTE: Null items will be in the array when keyCount != count */ for (int i=0; i= count) break; result [keys [i]] = items [keys [i]]; } } } boolean _hasItems () { return items != null; } void _initItems () { items = new TableItem [4]; if (COMPRESS_ITEMS) { if ((style & SWT.VIRTUAL) != 0) { keyCount = 0; keys = new int [4]; } } } /* NOTE: The array has already been grown to have space for the new item */ void _insertItem (int index, TableItem item, int count) { if (keys == null) { System.arraycopy (items, index, items, index + 1, count - index); items [index] = item; } else { int keyIndex = binarySearch (keys, 0, keyCount, index); if (keyIndex < 0) keyIndex = -keyIndex - 1; System.arraycopy(keys, keyIndex, keys, keyIndex + 1, keyCount - keyIndex); keys [keyIndex] = index; System.arraycopy(items, keyIndex, items, keyIndex + 1, keyCount - keyIndex); items [keyIndex] = item; keyCount++; for (int i=keyIndex + 1; iSelectionListener
* interface. *

* When widgetSelected is called, the item field of the event object is valid. * If the receiver has the SWT.CHECK style and the check selection changes, * the event object detail field contains the value SWT.CHECK. * widgetDefaultSelected is typically called when an item is double-clicked. * The item field of the event object is valid for default selection, but the detail field is not used. *

* * @param listener the listener which should be notified when the user changes the receiver's selection * * @exception IllegalArgumentException
    *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • *
* @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @see SelectionListener * @see #removeSelectionListener * @see SelectionEvent */ public void addSelectionListener (SelectionListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Selection,typedListener); addListener (SWT.DefaultSelection,typedListener); } int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) { return callWindowProc (hwnd, msg, wParam, lParam, false); } int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam, boolean forceSelect) { if (handle == 0) return 0; if (handle != hwnd) { return OS.CallWindowProc (HeaderProc, hwnd, msg, wParam, lParam); } int topIndex = 0; boolean checkSelection = false, checkActivate = false, redraw = false; switch (msg) { /* Keyboard messages */ /* * Feature in Windows. Windows sends LVN_ITEMACTIVATE from WM_KEYDOWN * instead of WM_CHAR. This means that application code that expects * to consume the key press and therefore avoid a SWT.DefaultSelection * event will fail. The fix is to ignore LVN_ITEMACTIVATE when it is * caused by WM_KEYDOWN and send SWT.DefaultSelection from WM_CHAR. */ case OS.WM_KEYDOWN: checkActivate = true; //FALL THROUGH case OS.WM_CHAR: case OS.WM_IME_CHAR: case OS.WM_KEYUP: case OS.WM_SYSCHAR: case OS.WM_SYSKEYDOWN: case OS.WM_SYSKEYUP: //FALL THROUGH /* Scroll messages */ case OS.WM_HSCROLL: case OS.WM_VSCROLL: //FALL THROUGH /* Resize messages */ case OS.WM_WINDOWPOSCHANGED: redraw = findImageControl () != null && getDrawing () && OS.IsWindowVisible (handle); if (redraw) { /* * Feature in Windows. When LVM_SETBKCOLOR is used with CLR_NONE * to make the background of the table transparent, drawing becomes * slow. The fix is to temporarily clear CLR_NONE when redraw is * turned off. */ OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, 0xFFFFFF); } //FALL THROUGH /* Mouse messages */ case OS.WM_LBUTTONDBLCLK: case OS.WM_LBUTTONDOWN: case OS.WM_LBUTTONUP: case OS.WM_MBUTTONDBLCLK: case OS.WM_MBUTTONDOWN: case OS.WM_MBUTTONUP: case OS.WM_MOUSEHOVER: case OS.WM_MOUSELEAVE: case OS.WM_MOUSEMOVE: case OS.WM_MOUSEWHEEL: case OS.WM_RBUTTONDBLCLK: case OS.WM_RBUTTONDOWN: case OS.WM_RBUTTONUP: case OS.WM_XBUTTONDBLCLK: case OS.WM_XBUTTONDOWN: case OS.WM_XBUTTONUP: checkSelection = true; //FALL THROUGH /* Other messages */ case OS.WM_SETFONT: case OS.WM_TIMER: { if (findImageControl () != null) { topIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0); } } } boolean oldSelected = wasSelected; if (checkSelection) wasSelected = false; if (checkActivate) ignoreActivate = true; /* * Bug in Windows. For some reason, when the WS_EX_COMPOSITED * style is set in a parent of a table and the header is visible, * Windows issues an endless stream of WM_PAINT messages. The * fix is to call BeginPaint() and EndPaint() outside of WM_PAINT * and pass the paint HDC in to the window proc. */ boolean fixPaint = false; if (msg == OS.WM_PAINT) { int bits0 = OS.GetWindowLong (handle, OS.GWL_STYLE); if ((bits0 & OS.LVS_NOCOLUMNHEADER) == 0) { int /*long*/ hwndParent = OS.GetParent (handle), hwndOwner = 0; while (hwndParent != 0) { int bits1 = OS.GetWindowLong (hwndParent, OS.GWL_EXSTYLE); if ((bits1 & OS.WS_EX_COMPOSITED) != 0) { fixPaint = true; break; } hwndOwner = OS.GetWindow (hwndParent, OS.GW_OWNER); if (hwndOwner != 0) break; hwndParent = OS.GetParent (hwndParent); } } } /* Remove the scroll bars that Windows keeps automatically adding */ boolean fixScroll = false; if ((style & SWT.H_SCROLL) == 0 || (style & SWT.V_SCROLL) == 0) { switch (msg) { case OS.WM_PAINT: case OS.WM_NCPAINT: case OS.WM_WINDOWPOSCHANGING: { int bits = OS.GetWindowLong (hwnd, OS.GWL_STYLE); if ((style & SWT.H_SCROLL) == 0 && (bits & OS.WS_HSCROLL) != 0) { fixScroll = true; bits &= ~OS.WS_HSCROLL; } if ((style & SWT.V_SCROLL) == 0 && (bits & OS.WS_VSCROLL) != 0) { fixScroll = true; bits &= ~OS.WS_VSCROLL; } if (fixScroll) OS.SetWindowLong (handle, OS.GWL_STYLE, bits); } } } int /*long*/ code = 0; if (fixPaint) { PAINTSTRUCT ps = new PAINTSTRUCT (); int /*long*/ hDC = OS.BeginPaint (hwnd, ps); code = OS.CallWindowProc (TableProc, hwnd, OS.WM_PAINT, hDC, lParam); OS.EndPaint (hwnd, ps); } else { code = OS.CallWindowProc (TableProc, hwnd, msg, wParam, lParam); } if (fixScroll) { int flags = OS.RDW_FRAME | OS.RDW_INVALIDATE; OS.RedrawWindow (handle, null, 0, flags); } if (checkActivate) ignoreActivate = false; if (checkSelection) { if (wasSelected || forceSelect) { Event event = new Event (); int index = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED); if (index != -1) event.item = _getItem (index); sendSelectionEvent (SWT.Selection, event, false); } wasSelected = oldSelected; } switch (msg) { /* Keyboard messages */ case OS.WM_KEYDOWN: case OS.WM_CHAR: case OS.WM_IME_CHAR: case OS.WM_KEYUP: case OS.WM_SYSCHAR: case OS.WM_SYSKEYDOWN: case OS.WM_SYSKEYUP: //FALL THROUGH /* Scroll messages */ case OS.WM_HSCROLL: case OS.WM_VSCROLL: //FALL THROUGH /* Resize messages */ case OS.WM_WINDOWPOSCHANGED: if (redraw) { OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, OS.CLR_NONE); OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); OS.InvalidateRect (handle, null, true); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); if (hwndHeader != 0) OS.InvalidateRect (hwndHeader, null, true); } //FALL THROUGH /* Mouse messages */ case OS.WM_LBUTTONDBLCLK: case OS.WM_LBUTTONDOWN: case OS.WM_LBUTTONUP: case OS.WM_MBUTTONDBLCLK: case OS.WM_MBUTTONDOWN: case OS.WM_MBUTTONUP: case OS.WM_MOUSEHOVER: case OS.WM_MOUSELEAVE: case OS.WM_MOUSEMOVE: case OS.WM_MOUSEWHEEL: case OS.WM_RBUTTONDBLCLK: case OS.WM_RBUTTONDOWN: case OS.WM_RBUTTONUP: case OS.WM_XBUTTONDBLCLK: case OS.WM_XBUTTONDOWN: case OS.WM_XBUTTONUP: //FALL THROUGH /* Other messages */ case OS.WM_SETFONT: case OS.WM_TIMER: { if (findImageControl () != null) { if (topIndex != OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)) { OS.InvalidateRect (handle, null, true); } } break; } case OS.WM_PAINT: painted = true; break; } return code; } static int checkStyle (int style) { /* * Feature in Windows. Even when WS_HSCROLL or * WS_VSCROLL is not specified, Windows creates * trees and tables with scroll bars. The fix * is to set H_SCROLL and V_SCROLL. * * NOTE: This code appears on all platforms so that * applications have consistent scroll bar behavior. */ if ((style & SWT.NO_SCROLL) == 0) { style |= SWT.H_SCROLL | SWT.V_SCROLL; } return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); } LRESULT CDDS_ITEMPOSTPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) { int /*long*/ hDC = nmcd.hdc; if (explorerTheme && !ignoreCustomDraw) { hotIndex = -1; if (hooks (SWT.EraseItem) && nmcd.left != nmcd.right) { OS.RestoreDC (hDC, -1); } } /* * Bug in Windows. When the table has the extended style * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with * CLR_NONE to make the table transparent, Windows fills * a black rectangle around any column that contains an * image. The fix is clear LVS_EX_FULLROWSELECT during * custom draw. * * NOTE: Since CDIS_FOCUS is cleared during custom draw, * it is necessary to draw the focus rectangle after the * item has been drawn. */ if (!ignoreCustomDraw && !ignoreDrawFocus && nmcd.left != nmcd.right) { if (OS.IsWindowVisible (handle) && OS.IsWindowEnabled (handle)) { if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) { if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) { int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) == 0) { // if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) { if (OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED) == nmcd.dwItemSpec) { if (handle == OS.GetFocus ()) { int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); if ((uiState & OS.UISF_HIDEFOCUS) == 0) { RECT rect = new RECT (); rect.left = OS.LVIR_BOUNDS; boolean oldIgnore = ignoreCustomDraw; ignoreCustomDraw = true; OS.SendMessage (handle, OS. LVM_GETITEMRECT, nmcd.dwItemSpec, rect); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); int index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0); RECT itemRect = new RECT (); if (index == 0) { itemRect.left = OS.LVIR_LABEL; OS.SendMessage (handle, OS. LVM_GETITEMRECT, index, itemRect); } else { itemRect.top = index; itemRect.left = OS.LVIR_ICON; OS.SendMessage (handle, OS. LVM_GETSUBITEMRECT, nmcd.dwItemSpec, itemRect); } ignoreCustomDraw = oldIgnore; rect.left = itemRect.left; OS.DrawFocusRect (nmcd.hdc, rect); } } } } } } } } return null; } LRESULT CDDS_ITEMPREPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) { /* * Bug in Windows. When the table has the extended style * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with * CLR_NONE to make the table transparent, Windows fills * a black rectangle around any column that contains an * image. The fix is clear LVS_EX_FULLROWSELECT during * custom draw. * * NOTE: It is also necessary to clear CDIS_FOCUS to stop * the table from drawing the focus rectangle around the * first item instead of the full row. */ if (!ignoreCustomDraw) { if (OS.IsWindowVisible (handle) && OS.IsWindowEnabled (handle)) { if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) { if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) { int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) == 0) { if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) { nmcd.uItemState &= ~OS.CDIS_FOCUS; OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); } } } } } } if (explorerTheme && !ignoreCustomDraw) { hotIndex = (nmcd.uItemState & OS.CDIS_HOT) != 0 ? (int)/*64*/nmcd.dwItemSpec : -1; if (hooks (SWT.EraseItem) && nmcd.left != nmcd.right) { OS.SaveDC (nmcd.hdc); int /*long*/ hrgn = OS.CreateRectRgn (0, 0, 0, 0); OS.SelectClipRgn (nmcd.hdc, hrgn); OS.DeleteObject (hrgn); } } return new LRESULT (OS.CDRF_NOTIFYSUBITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT); } LRESULT CDDS_POSTPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) { if (ignoreCustomDraw) return null; /* * Bug in Windows. When the table has the extended style * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with * CLR_NONE to make the table transparent, Windows fills * a black rectangle around any column that contains an * image. The fix is clear LVS_EX_FULLROWSELECT during * custom draw. */ if (--customCount == 0 && OS.IsWindowVisible (handle)) { if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) { if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) { int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) == 0) { int bits = OS.LVS_EX_FULLROWSELECT; /* * Feature in Windows. When LVM_SETEXTENDEDLISTVIEWSTYLE is * used to set or clear the extended style bits and the table * has a tooltip, the tooltip is hidden. The fix is to clear * the tooltip before setting the bits and then reset it. */ int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_SETTOOLTIPS, 0, 0); if (OS.IsWinCE) { RECT rect = new RECT (); boolean damaged = OS.GetUpdateRect (handle, rect, true); OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits); OS.ValidateRect (handle, null); if (damaged) OS.InvalidateRect (handle, rect, true); } else { int /*long*/ rgn = OS.CreateRectRgn (0, 0, 0, 0); int result = OS.GetUpdateRgn (handle, rgn, true); OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits); OS.ValidateRect (handle, null); if (result != OS.NULLREGION) OS.InvalidateRgn (handle, rgn, true); OS.DeleteObject (rgn); } /* * Bug in Windows. Despite the documentation, LVM_SETTOOLTIPS * uses WPARAM instead of LPARAM for the new tooltip The fix * is to put the tooltip in both parameters. */ hwndToolTip = OS.SendMessage (handle, OS.LVM_SETTOOLTIPS, hwndToolTip, hwndToolTip); } } } } return null; } LRESULT CDDS_PREPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) { if (ignoreCustomDraw) { return new LRESULT (OS.CDRF_NOTIFYITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT); } /* * Bug in Windows. When the table has the extended style * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with * CLR_NONE to make the table transparent, Windows fills * a black rectangle around any column that contains an * image. The fix is clear LVS_EX_FULLROWSELECT during * custom draw. */ if (customCount++ == 0 && OS.IsWindowVisible (handle)) { if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) { if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) { int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) != 0) { int bits = OS.LVS_EX_FULLROWSELECT; /* * Feature in Windows. When LVM_SETEXTENDEDLISTVIEWSTYLE is * used to set or clear the extended style bits and the table * has a tooltip, the tooltip is hidden. The fix is to clear * the tooltip before setting the bits and then reset it. */ int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_SETTOOLTIPS, 0, 0); if (OS.IsWinCE) { RECT rect = new RECT (); boolean damaged = OS.GetUpdateRect (handle, rect, true); OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, 0); OS.ValidateRect (handle, null); if (damaged) OS.InvalidateRect (handle, rect, true); } else { int /*long*/ rgn = OS.CreateRectRgn (0, 0, 0, 0); int result = OS.GetUpdateRgn (handle, rgn, true); OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, 0); OS.ValidateRect (handle, null); if (result != OS.NULLREGION) OS.InvalidateRgn (handle, rgn, true); OS.DeleteObject (rgn); } /* * Bug in Windows. Despite the documentation, LVM_SETTOOLTIPS * uses WPARAM instead of LPARAM for the new tooltip The fix * is to put the tooltip in both parameters. */ hwndToolTip = OS.SendMessage (handle, OS.LVM_SETTOOLTIPS, hwndToolTip, hwndToolTip); } } } } if (OS.IsWindowVisible (handle)) { boolean draw = true; /* * Feature in Windows. On Vista using the explorer theme, * Windows draws a vertical line to separate columns. When * there is only a single column, the line looks strange. * The fix is to draw the background using custom draw. */ if (explorerTheme && columnCount == 0) { int /*long*/ hDC = nmcd.hdc; RECT rect = new RECT (); OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); if (OS.IsWindowEnabled (handle) || findImageControl () != null) { drawBackground (hDC, rect); } else { fillBackground (hDC, OS.GetSysColor (OS.COLOR_3DFACE), rect); } draw = false; } if (draw) { Control control = findBackgroundControl (); if (control != null && control.backgroundImage != null) { RECT rect = new RECT (); OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); fillImageBackground (nmcd.hdc, control, rect, 0, 0); } else { if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) { if (OS.IsWindowEnabled (handle)) { RECT rect = new RECT (); OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); if (control == null) control = this; fillBackground (nmcd.hdc, control.getBackgroundPixel (), rect); if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { if (sortColumn != null && sortDirection != SWT.NONE) { int index = indexOf (sortColumn); if (index != -1) { parent.forceResize (); int clrSortBk = getSortColumnPixel (); RECT columnRect = new RECT (), headerRect = new RECT (); OS.GetClientRect (handle, columnRect); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect) != 0) { OS.MapWindowPoints (hwndHeader, handle, headerRect, 2); columnRect.left = headerRect.left; columnRect.right = headerRect.right; if (OS.IntersectRect(columnRect, columnRect, rect)) { fillBackground (nmcd.hdc, clrSortBk, columnRect); } } } } } } } } } } return new LRESULT (OS.CDRF_NOTIFYITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT); } LRESULT CDDS_SUBITEMPOSTPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) { if (ignoreCustomDraw) return null; if (nmcd.left == nmcd.right) return new LRESULT (OS.CDRF_DODEFAULT); int /*long*/ hDC = nmcd.hdc; if (ignoreDrawForeground) OS.RestoreDC (hDC, -1); if (OS.IsWindowVisible (handle)) { /* * Feature in Windows. When there is a sort column, the sort column * color draws on top of the background color for an item. The fix * is to clear the sort column in CDDS_SUBITEMPREPAINT, and reset it * in CDDS_SUBITEMPOSTPAINT. */ if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) != OS.CLR_NONE) { if ((sortDirection & (SWT.UP | SWT.DOWN)) != 0) { if (sortColumn != null && !sortColumn.isDisposed ()) { int oldColumn = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOLUMN, 0, 0); if (oldColumn == -1) { int newColumn = indexOf (sortColumn); int result = 0; int /*long*/ rgn = 0; if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { rgn = OS.CreateRectRgn (0, 0, 0, 0); result = OS.GetUpdateRgn (handle, rgn, true); } OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, newColumn, 0); if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { OS.ValidateRect (handle, null); if (result != OS.NULLREGION) OS.InvalidateRgn (handle, rgn, true); OS.DeleteObject (rgn); } } } } } if (hooks (SWT.PaintItem)) { TableItem item = _getItem ((int)/*64*/nmcd.dwItemSpec); sendPaintItemEvent (item, nmcd); //widget could be disposed at this point } if (!ignoreDrawFocus && focusRect != null) { OS.SetTextColor (nmcd.hdc, 0); OS.SetBkColor (nmcd.hdc, 0xFFFFFF); OS.DrawFocusRect (nmcd.hdc, focusRect); focusRect = null; } } return null; } LRESULT CDDS_SUBITEMPREPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) { int /*long*/ hDC = nmcd.hdc; if (explorerTheme && !ignoreCustomDraw && hooks (SWT.EraseItem) && (nmcd.left != nmcd.right)) { OS.RestoreDC (hDC, -1); } /* * Feature in Windows. When a new table item is inserted * using LVM_INSERTITEM in a table that is transparent * (ie. LVM_SETBKCOLOR has been called with CLR_NONE), * TVM_INSERTITEM calls NM_CUSTOMDRAW before the new item * has been added to the array. The fix is to check for * null. * * NOTE: Force the item to be created if it does not exist. */ TableItem item = _getItem ((int)/*64*/nmcd.dwItemSpec); if (item == null || item.isDisposed ()) return null; int /*long*/ hFont = item.fontHandle (nmcd.iSubItem); if (hFont != -1) OS.SelectObject (hDC, hFont); if (ignoreCustomDraw || (nmcd.left == nmcd.right)) { return new LRESULT (hFont == -1 ? OS.CDRF_DODEFAULT : OS.CDRF_NEWFONT); } int code = OS.CDRF_DODEFAULT; selectionForeground = -1; ignoreDrawForeground = ignoreDrawSelection = ignoreDrawFocus = ignoreDrawBackground = false; if (OS.IsWindowVisible (handle)) { Event measureEvent = null; if (hooks (SWT.MeasureItem)) { measureEvent = sendMeasureItemEvent (item, (int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, nmcd.hdc); if (isDisposed () || item.isDisposed ()) return null; } if (hooks (SWT.EraseItem)) { sendEraseItemEvent (item, nmcd, lParam, measureEvent); if (isDisposed () || item.isDisposed ()) return null; code |= OS.CDRF_NOTIFYPOSTPAINT; } if (ignoreDrawForeground || hooks (SWT.PaintItem)) code |= OS.CDRF_NOTIFYPOSTPAINT; } 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; if (selectionForeground != -1) clrText = selectionForeground; /* * Bug in Windows. When the table has the extended style * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with * CLR_NONE to make the table transparent, Windows draws * a black rectangle around any column that contains an * image. The fix is emulate LVS_EX_FULLROWSELECT by * drawing the selection. */ if (OS.IsWindowVisible (handle) && OS.IsWindowEnabled (handle)) { if (!explorerTheme && !ignoreDrawSelection && (style & SWT.FULL_SELECTION) != 0) { int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((bits & OS.LVS_EX_FULLROWSELECT) == 0) { /* * 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 = (int)/*64*/nmcd.dwItemSpec; int /*long*/ result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem); if ((result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0)) { int clrSelection = -1; if (nmcd.iSubItem == 0) { if (OS.GetFocus () == handle || display.getHighContrast ()) { clrSelection = OS.GetSysColor (OS.COLOR_HIGHLIGHT); } else { if ((style & SWT.HIDE_SELECTION) == 0) { clrSelection = OS.GetSysColor (OS.COLOR_3DFACE); } } } else { if (OS.GetFocus () == handle || display.getHighContrast ()) { clrText = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT); clrTextBk = clrSelection = OS.GetSysColor (OS.COLOR_HIGHLIGHT); } else { if ((style & SWT.HIDE_SELECTION) == 0) { clrTextBk = clrSelection = OS.GetSysColor (OS.COLOR_3DFACE); } } } if (clrSelection != -1) { RECT rect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, nmcd.iSubItem != 0, true, false, hDC); fillBackground (hDC, clrSelection, rect); } } } } } if (!ignoreDrawForeground) { /* * Bug in Windows. When the attributes are for one cell in a table, * Windows does not reset them for the next cell. As a result, all * subsequent cells are drawn using the previous font, foreground and * background colors. The fix is to set the all attributes when any * attribute could have changed. */ boolean hasAttributes = true; if (hFont == -1 && clrText == -1 && clrTextBk == -1) { if (item.cellForeground == null && item.cellBackground == null && item.cellFont == null) { int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); int count = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0); if (count == 1) hasAttributes = false; } } if (hasAttributes) { if (hFont == -1) hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); OS.SelectObject (hDC, hFont); if (OS.IsWindowEnabled (handle)) { nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText; if (clrTextBk == -1) { nmcd.clrTextBk = OS.CLR_NONE; if (selectionForeground == -1) { Control control = findBackgroundControl (); if (control == null) control = this; if (control.backgroundImage == null) { if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) != OS.CLR_NONE) { nmcd.clrTextBk = control.getBackgroundPixel (); } } } } else { nmcd.clrTextBk = selectionForeground != -1 ? OS.CLR_NONE : clrTextBk; } OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); } code |= OS.CDRF_NEWFONT; } } if (OS.IsWindowEnabled (handle)) { /* * Feature in Windows. When there is a sort column, the sort column * color draws on top of the background color for an item. The fix * is to clear the sort column in CDDS_SUBITEMPREPAINT, and reset it * in CDDS_SUBITEMPOSTPAINT. */ if (clrTextBk != -1) { int oldColumn = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOLUMN, 0, 0); if (oldColumn != -1 && oldColumn == nmcd.iSubItem) { int result = 0; int /*long*/ rgn = 0; if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { rgn = OS.CreateRectRgn (0, 0, 0, 0); result = OS.GetUpdateRgn (handle, rgn, true); } OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, -1, 0); if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { OS.ValidateRect (handle, null); if (result != OS.NULLREGION) OS.InvalidateRgn (handle, rgn, true); OS.DeleteObject (rgn); } code |= OS.CDRF_NOTIFYPOSTPAINT; } } } else { /* * Feature in Windows. When the table is disabled, it draws * with a gray background but does not gray the text. The fix * is to explicitly gray the text. */ nmcd.clrText = OS.GetSysColor (OS.COLOR_GRAYTEXT); if (findImageControl () != null) { nmcd.clrTextBk = OS.CLR_NONE; } else { nmcd.clrTextBk = OS.GetSysColor (OS.COLOR_3DFACE); } nmcd.uItemState &= ~OS.CDIS_SELECTED; OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); code |= OS.CDRF_NEWFONT; } return new LRESULT (code); } void checkBuffered () { super.checkBuffered (); if (OS.COMCTL32_MAJOR >= 6) style |= SWT.DOUBLE_BUFFERED; if ((style & SWT.VIRTUAL) != 0) style |= SWT.DOUBLE_BUFFERED; } boolean checkData (TableItem item, boolean redraw) { if ((style & SWT.VIRTUAL) == 0) return true; return checkData (item, indexOf (item), redraw); } boolean checkData (TableItem item, int index, boolean redraw) { if ((style & SWT.VIRTUAL) == 0) return true; if (!item.cached) { item.cached = true; Event event = new Event (); event.item = item; event.index = index; currentItem = item; sendEvent (SWT.SetData, event); //widget could be disposed at this point currentItem = null; if (isDisposed () || item.isDisposed ()) return false; if (redraw) { if (!setScrollWidth (item, false)) { item.redraw (); } } } return true; } boolean checkHandle (int /*long*/ hwnd) { if (hwnd == handle) return true; return hwnd == OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); } protected void checkSubclass () { if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); } /** * Clears the item at the given zero-relative index in the receiver. * The text, icon and other attributes of the item are set to the default * value. If the table was created with the SWT.VIRTUAL style, * these attributes are requested again as needed. * * @param index the index of the item to clear * * @exception IllegalArgumentException
    *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
  • *
* @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clear (int index) { checkWidget (); int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE); TableItem item = _getItem (index, false); if (item != null) { if (item != currentItem) item.clear (); /* * Bug in Windows. Despite the fact that every item in the * table always has LPSTR_TEXTCALLBACK, Windows caches the * bounds for the selected items. This means that * when you change the string to be something else, Windows * correctly asks you for the new string but when the item * is selected, the selection draws using the bounds of the * previous item. The fix is to reset LPSTR_TEXTCALLBACK * even though it has not changed, causing Windows to flush * cached bounds. */ if ((style & SWT.VIRTUAL) == 0 && item.cached) { LVITEM lvItem = new LVITEM (); lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT; lvItem.pszText = OS.LPSTR_TEXTCALLBACK; lvItem.iItem = index; OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem); item.cached = false; } if (currentItem == null && getDrawing () && OS.IsWindowVisible (handle)) { OS.SendMessage (handle, OS.LVM_REDRAWITEMS, index, index); } setScrollWidth (item, false); } } /** * Removes the items from the receiver which are between the given * zero-relative start and end indices (inclusive). The text, icon * and other attributes of the items are set to their default values. * If the table was created with the SWT.VIRTUAL style, * these attributes are requested again as needed. * * @param start the start index of the item to clear * @param end the end index of the item to clear * * @exception IllegalArgumentException
    *
  • ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)
  • *
* @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clear (int start, int end) { checkWidget (); if (start > end) return; int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (!(0 <= start && start <= end && end < count)) { error (SWT.ERROR_INVALID_RANGE); } if (start == 0 && end == count - 1) { clearAll (); } else { LVITEM lvItem = null; boolean cleared = false; for (int i=start; i<=end; i++) { TableItem item = _getItem (i, false); if (item != null) { if (item != currentItem) { cleared = true; item.clear (); } /* * Bug in Windows. Despite the fact that every item in the * table always has LPSTR_TEXTCALLBACK, Windows caches the * bounds for the selected items. This means that * when you change the string to be something else, Windows * correctly asks you for the new string but when the item * is selected, the selection draws using the bounds of the * previous item. The fix is to reset LPSTR_TEXTCALLBACK * even though it has not changed, causing Windows to flush * cached bounds. */ if ((style & SWT.VIRTUAL) == 0 && item.cached) { if (lvItem == null) { lvItem = new LVITEM (); lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT; lvItem.pszText = OS.LPSTR_TEXTCALLBACK; } lvItem.iItem = i; OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem); item.cached = false; } } } if (cleared) { if (currentItem == null && getDrawing () && OS.IsWindowVisible (handle)) { OS.SendMessage (handle, OS.LVM_REDRAWITEMS, start, end); } TableItem item = start == end ? _getItem (start, false) : null; setScrollWidth (item, false); } } } /** * Clears the items at the given zero-relative indices in the receiver. * The text, icon and other attributes of the items are set to their default * values. If the table was created with the SWT.VIRTUAL style, * these attributes are requested again as needed. * * @param indices the array of indices of the items * * @exception IllegalArgumentException
    *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
  • *
  • ERROR_NULL_ARGUMENT - if the indices array is null
  • *
* @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clear (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); if (indices.length == 0) return; int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); for (int i=0; iSWT.VIRTUAL style, these * attributes are requested again as needed. * * @exception SWTException
    *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • *
* * @see SWT#VIRTUAL * @see SWT#SetData * * @since 3.0 */ public void clearAll () { checkWidget (); LVITEM lvItem = null; boolean cleared = false; int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); for (int i=0; i= OS.VERSION (6, 0) && OS.IsAppThemed ()) { explorerTheme = true; OS.SetWindowTheme (handle, Display.EXPLORER, null); } } /* Get the header window proc */ if (HeaderProc == 0) { int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); HeaderProc = OS.GetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC); } /* * Feature in Windows. In version 5.8 of COMCTL32.DLL, * if the font is changed for an item, the bounds for the * item are not updated, causing the text to be clipped. * The fix is to detect the version of COMCTL32.DLL, and * if it is one of the versions with the problem, then * use version 5.00 of the control (a version that does * not have the problem). This is the recommended work * around from the MSDN. */ if (!OS.IsWinCE) { if (OS.COMCTL32_MAJOR < 6) { OS.SendMessage (handle, OS.CCM_SETVERSION, 5, 0); } } /* * This code is intentionally commented. According to * the documentation, setting the default item size is * supposed to improve performance. By experimentation, * this does not seem to have much of an effect. */ // OS.SendMessage (handle, OS.LVM_SETITEMCOUNT, 1024 * 2, 0); /* Set the checkbox image list */ if ((style & SWT.CHECK) != 0) { int /*long*/ empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0); int /*long*/ oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0); int width = OS.HIWORD (oneItem) - OS.HIWORD (empty), height = width; setCheckboxImageList (width, height, false); OS.SendMessage (handle, OS. LVM_SETCALLBACKMASK, OS.LVIS_STATEIMAGEMASK, 0); } /* * Feature in Windows. When the control is created, * it does not use the default system font. A new HFONT * is created and destroyed when the control is destroyed. * This means that a program that queries the font from * this control, uses the font in another control and then * destroys this control will have the font unexpectedly * destroyed in the other control. The fix is to assign * the font ourselves each time the control is created. * The control will not destroy a font that it did not * create. */ int /*long*/ hFont = OS.GetStockObject (OS.SYSTEM_FONT); OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0); /* * Bug in Windows. When the first column is inserted * without setting the header text, Windows will never * allow the header text for the first column to be set. * The fix is to set the text to an empty string when * the column is inserted. */ LVCOLUMN lvColumn = new LVCOLUMN (); lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_WIDTH; int /*long*/ hHeap = OS.GetProcessHeap (); int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof); lvColumn.pszText = pszText; OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, 0, lvColumn); OS.HeapFree (hHeap, 0, pszText); /* Set the extended style bits */ int bits1 = OS.LVS_EX_LABELTIP; if ((style & SWT.FULL_SELECTION) != 0) bits1 |= OS.LVS_EX_FULLROWSELECT; if (OS.COMCTL32_MAJOR >= 6) bits1 |= OS.LVS_EX_DOUBLEBUFFER; OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits1, bits1); /* * Feature in Windows. Windows does not explicitly set the orientation of * the header. Instead, the orientation is inherited when WS_EX_LAYOUTRTL * is specified for the table. This means that when both WS_EX_LAYOUTRTL * and WS_EX_NOINHERITLAYOUT are specified for the table, the header will * not be oriented correctly. The fix is to explicitly set the orientation * for the header. * * NOTE: WS_EX_LAYOUTRTL is not supported on Windows NT. */ if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) { if ((style & SWT.RIGHT_TO_LEFT) != 0) { int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); int bits2 = OS.GetWindowLong (hwndHeader, OS.GWL_EXSTYLE); OS.SetWindowLong (hwndHeader, OS.GWL_EXSTYLE, bits2 | OS.WS_EX_LAYOUTRTL); int /*long*/ hwndTooltop = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0); int bits3 = OS.GetWindowLong (hwndTooltop, OS.GWL_EXSTYLE); OS.SetWindowLong (hwndTooltop, OS.GWL_EXSTYLE, bits3 | OS.WS_EX_LAYOUTRTL); } } } void createHeaderToolTips () { if (OS.IsWinCE) return; if (headerToolTipHandle != 0) return; int bits = 0; if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) { if ((style & SWT.RIGHT_TO_LEFT) != 0) bits |= OS.WS_EX_LAYOUTRTL; } headerToolTipHandle = OS.CreateWindowEx ( bits, new TCHAR (0, OS.TOOLTIPS_CLASS, true), null, OS.TTS_NOPREFIX, OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0, handle, 0, OS.GetModuleHandle (null), null); if (headerToolTipHandle == 0) error (SWT.ERROR_NO_HANDLES); /* * Feature in Windows. Despite the fact that the * tool tip text contains \r\n, the tooltip will * not honour the new line unless TTM_SETMAXTIPWIDTH * is set. The fix is to set TTM_SETMAXTIPWIDTH to * a large value. */ OS.SendMessage (headerToolTipHandle, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF); } void createItem (TableColumn column, int index) { if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE); int oldColumn = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOLUMN, 0, 0); if (oldColumn >= index) { OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, oldColumn + 1, 0); } if (columnCount == columns.length) { TableColumn [] newColumns = new TableColumn [columns.length + 4]; System.arraycopy (columns, 0, newColumns, 0, columns.length); columns = newColumns; } int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); for (int i=0; i 1) { LVCOLUMN lvColumn = new LVCOLUMN (); lvColumn.mask = OS.LVCF_WIDTH; OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, 1, lvColumn); OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, lvColumn); int width = lvColumn.cx; int cchTextMax = 1024; int /*long*/ hHeap = OS.GetProcessHeap (); int byteCount = cchTextMax * TCHAR.sizeof; int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_IMAGE | OS.LVCF_WIDTH | OS.LVCF_FMT; lvColumn.pszText = pszText; lvColumn.cchTextMax = cchTextMax; OS.SendMessage (handle, OS.LVM_GETCOLUMN, 0, lvColumn); OS.SendMessage (handle, OS.LVM_SETCOLUMN, 1, lvColumn); lvColumn.fmt = OS.LVCFMT_IMAGE; lvColumn.cx = width; lvColumn.iImage = OS.I_IMAGENONE; lvColumn.pszText = lvColumn.cchTextMax = 0; OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn); lvColumn.mask = OS.LVCF_FMT; lvColumn.fmt = OS.LVCFMT_LEFT; OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn); if (pszText != 0) OS.HeapFree (hHeap, 0, pszText); } else { OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, 0); } /* * Bug in Windows. Despite the fact that every item in the * table always has LPSTR_TEXTCALLBACK, Windows caches the * bounds for the selected items. This means that * when you change the string to be something else, Windows * correctly asks you for the new string but when the item * is selected, the selection draws using the bounds of the * previous item. The fix is to reset LPSTR_TEXTCALLBACK * even though it has not changed, causing Windows to flush * cached bounds. */ if ((style & SWT.VIRTUAL) == 0) { LVITEM lvItem = new LVITEM (); lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE; lvItem.pszText = OS.LPSTR_TEXTCALLBACK; lvItem.iImage = OS.I_IMAGECALLBACK; for (int i=0; i *
  • ERROR_NULL_ARGUMENT - if the set of indices is null
  • * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void deselect (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); if (indices.length == 0) return; LVITEM lvItem = new LVITEM (); lvItem.stateMask = OS.LVIS_SELECTED; for (int i=0; i= 0) { ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, indices [i], lvItem); ignoreSelect = false; } } } /** * Deselects the item at the given zero-relative index in the receiver. * If the item at the index was already deselected, it remains * deselected. Indices that are out of range are ignored. * * @param index the index of the item to deselect * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void deselect (int index) { checkWidget (); /* * An index of -1 will apply the change to all * items. Ensure that index is greater than -1. */ if (index < 0) return; LVITEM lvItem = new LVITEM (); lvItem.stateMask = OS.LVIS_SELECTED; ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem); ignoreSelect = false; } /** * Deselects the items at the given zero-relative indices in the receiver. * If the item at the given zero-relative index in the receiver * is selected, it is deselected. If the item at the index * was not selected, it remains deselected. The range of the * indices is inclusive. Indices that are out of range are ignored. * * @param start the start index of the items to deselect * @param end the end index of the items to deselect * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void deselect (int start, int end) { checkWidget (); int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (start == 0 && end == count - 1) { deselectAll (); } else { LVITEM lvItem = new LVITEM (); lvItem.stateMask = OS.LVIS_SELECTED; /* * An index of -1 will apply the change to all * items. Ensure that indices are greater than -1. */ start = Math.max (0, start); for (int i=start; i<=end; i++) { ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, i, lvItem); ignoreSelect = false; } } } /** * Deselects all selected items in the receiver. * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void deselectAll () { checkWidget (); LVITEM lvItem = new LVITEM (); lvItem.mask = OS.LVIF_STATE; lvItem.stateMask = OS.LVIS_SELECTED; ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, -1, lvItem); ignoreSelect = false; } void destroyItem (TableColumn column) { int index = 0; while (index < columnCount) { if (columns [index] == column) break; index++; } int oldColumn = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOLUMN, 0, 0); if (oldColumn == index) { OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, -1, 0); } else { if (oldColumn > index) { OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, oldColumn - 1, 0); } } int orderIndex = 0; int [] oldOrder = new int [columnCount]; OS.SendMessage (handle, OS.LVM_GETCOLUMNORDERARRAY, columnCount, oldOrder); while (orderIndex < columnCount) { if (oldOrder [orderIndex] == index) break; orderIndex++; } ignoreColumnResize = true; boolean first = false; if (index == 0) { first = true; /* * Changing the content of a column using LVM_SETCOLUMN causes * the table control to send paint events. At this point the * partially disposed column is still part of the table and * paint handler can try to access it. This can cause exceptions. * The fix is to turn redraw off. */ setRedraw (false); if (columnCount > 1) { index = 1; int cchTextMax = 1024; int /*long*/ hHeap = OS.GetProcessHeap (); int byteCount = cchTextMax * TCHAR.sizeof; int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); LVCOLUMN lvColumn = new LVCOLUMN (); lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_IMAGE | OS.LVCF_WIDTH | OS.LVCF_FMT; lvColumn.pszText = pszText; lvColumn.cchTextMax = cchTextMax; OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, lvColumn); lvColumn.fmt &= ~(OS.LVCFMT_CENTER | OS.LVCFMT_RIGHT); lvColumn.fmt |= OS.LVCFMT_LEFT; OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn); if (pszText != 0) OS.HeapFree (hHeap, 0, pszText); } else { int /*long*/ hHeap = OS.GetProcessHeap (); int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof); LVCOLUMN lvColumn = new LVCOLUMN (); lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_IMAGE | OS.LVCF_WIDTH | OS.LVCF_FMT; lvColumn.pszText = pszText; lvColumn.iImage = OS.I_IMAGENONE; lvColumn.fmt = OS.LVCFMT_LEFT; OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn); if (pszText != 0) OS.HeapFree (hHeap, 0, pszText); if (OS.COMCTL32_MAJOR >= 6) { HDITEM hdItem = new HDITEM (); hdItem.mask = OS.HDI_FORMAT; hdItem.fmt = OS.HDF_LEFT; int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem); } } setRedraw (true); /* * Bug in Windows. Despite the fact that every item in the * table always has LPSTR_TEXTCALLBACK, Windows caches the * bounds for the selected items. This means that * when you change the string to be something else, Windows * correctly asks you for the new string but when the item * is selected, the selection draws using the bounds of the * previous item. The fix is to reset LPSTR_TEXTCALLBACK * even though it has not changed, causing Windows to flush * cached bounds. */ if ((style & SWT.VIRTUAL) == 0) { LVITEM lvItem = new LVITEM (); lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE; lvItem.pszText = OS.LPSTR_TEXTCALLBACK; lvItem.iImage = OS.I_IMAGECALLBACK; int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); for (int i=0; i 1) { if (OS.SendMessage (handle, OS.LVM_DELETECOLUMN, index, 0) == 0) { error (SWT.ERROR_ITEM_NOT_REMOVED); } } if (first) index = 0; System.arraycopy (columns, index + 1, columns, index, --columnCount - index); columns [columnCount] = null; int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); for (int i=0; i= OS.VERSION (5, 80)) return; int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((bits & OS.LVS_EX_GRIDLINES) == 0) return; bits = OS.GetWindowLong (handle, OS.GWL_STYLE); if ((bits & OS.LVS_NOCOLUMNHEADER) != 0) return; /* * Bug in Windows. Making any change to an item that * changes the item height of a table while the table * is scrolled can cause the lines to draw incorrectly. * This happens even when the lines are not currently * visible and are shown afterwards. The fix is to * save the top index, scroll to the top of the table * and then restore the original top index. */ int topIndex = getTopIndex (); if (fixScroll && topIndex != 0) { setRedraw (false); setTopIndex (0); } int /*long*/ hOldList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0); if (hOldList != 0) return; int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); RECT rect = new RECT (); OS.GetWindowRect (hwndHeader, rect); int height = rect.bottom - rect.top - 1; int /*long*/ hImageList = OS.ImageList_Create (1, height, 0, 0, 0); OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList); fixCheckboxImageList (false); OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0); if (headerImageList != null) { int /*long*/ hHeaderImageList = headerImageList.getHandle (); OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hHeaderImageList); } OS.ImageList_Destroy (hImageList); if (fixScroll && topIndex != 0) { setTopIndex (topIndex); setRedraw (true); } } /** * Returns the column at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * Columns are returned in the order that they were created. * If no TableColumns were created by the programmer, * this method will throw ERROR_INVALID_RANGE despite * the fact that a single column of data may be visible in the table. * This occurs when the programmer uses the table like a list, adding * items but never creating a column. * * @param index the index of the column to return * @return the column at the given index * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#getColumnOrder() * @see Table#setColumnOrder(int[]) * @see TableColumn#getMoveable() * @see TableColumn#setMoveable(boolean) * @see SWT#Move */ public TableColumn getColumn (int index) { checkWidget (); if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE); return columns [index]; } /** * Returns the number of columns contained in the receiver. * If no TableColumns were created by the programmer, * this value is zero, despite the fact that visually, one column * of items may be visible. This occurs when the programmer uses * the table like a list, adding items but never creating a column. * * @return the number of columns * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int getColumnCount () { checkWidget (); return columnCount; } /** * Returns an array of zero-relative integers that map * the creation order of the receiver's items to the * order in which they are currently being displayed. *

    * Specifically, the indices of the returned array represent * the current visual order of the items, and the contents * of the array represent the creation order of the items. *

    * Note: This is not the actual structure used by the receiver * to maintain its list of items, so modifying the array will * not affect the receiver. *

    * * @return the current visual order of the receiver's items * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#setColumnOrder(int[]) * @see TableColumn#getMoveable() * @see TableColumn#setMoveable(boolean) * @see SWT#Move * * @since 3.1 */ public int[] getColumnOrder () { checkWidget (); if (columnCount == 0) return new int [0]; int [] order = new int [columnCount]; OS.SendMessage (handle, OS.LVM_GETCOLUMNORDERARRAY, columnCount, order); return order; } /** * Returns an array of TableColumns which are the * columns in the receiver. Columns are returned in the order * that they were created. If no TableColumns were * created by the programmer, the array is empty, despite the fact * that visually, one column of items may be visible. This occurs * when the programmer uses the table like a list, adding items but * never creating a column. *

    * Note: This is not the actual structure used by the receiver * to maintain its list of items, so modifying the array will * not affect the receiver. *

    * * @return the items in the receiver * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#getColumnOrder() * @see Table#setColumnOrder(int[]) * @see TableColumn#getMoveable() * @see TableColumn#setMoveable(boolean) * @see SWT#Move */ public TableColumn [] getColumns () { checkWidget (); TableColumn [] result = new TableColumn [columnCount]; System.arraycopy (columns, 0, result, 0, columnCount); return result; } int getFocusIndex () { // checkWidget (); return (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED); } /** * Returns the width in pixels of a grid line. * * @return the width of a grid line in pixels * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int getGridLineWidth () { checkWidget (); return GRID_WIDTH; } /** * Returns the height of the receiver's header * * @return the height of the header or zero if the header is not visible * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 2.0 */ public int getHeaderHeight () { checkWidget (); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); if (hwndHeader == 0) return 0; RECT rect = new RECT (); OS.GetWindowRect (hwndHeader, rect); return rect.bottom - rect.top; } /** * Returns true if the receiver's header is visible, * and false otherwise. *

    * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, this method * may still indicate that it is considered visible even though * it may not actually be showing. *

    * * @return the receiver's header's visibility state * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public boolean getHeaderVisible () { checkWidget (); int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); return (bits & OS.LVS_NOCOLUMNHEADER) == 0; } /** * Returns the item at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * * @param index the index of the item to return * @return the item at the given index * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public TableItem getItem (int index) { checkWidget (); int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE); return _getItem (index); } /** * Returns the item at the given point in the receiver * or null if no such item exists. The point is in the * coordinate system of the receiver. *

    * The item that is returned represents an item that could be selected by the user. * For example, if selection only occurs in items in the first column, then null is * returned if the point is outside of the item. * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy, * determines the extent of the selection. *

    * * @param point the point used to locate the item * @return the item at the given point, or null if the point is not in a selectable item * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the point is null
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public TableItem getItem (Point point) { checkWidget (); if (point == null) error (SWT.ERROR_NULL_ARGUMENT); int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (count == 0) return null; LVHITTESTINFO pinfo = new LVHITTESTINFO (); pinfo.x = point.x; pinfo.y = point.y; if ((style & SWT.FULL_SELECTION) == 0) { if (hooks (SWT.MeasureItem)) { /* * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest * a point that is above the table, instead of returning -1 to * indicate that the hittest failed, a negative index is returned. * The fix is to consider any value that is negative a failure. */ if (OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo) < 0) { RECT rect = new RECT (); rect.left = OS.LVIR_ICON; ignoreCustomDraw = true; int /*long*/ code = OS.SendMessage (handle, OS.LVM_GETITEMRECT, 0, rect); ignoreCustomDraw = false; if (code != 0) { pinfo.x = rect.left; /* * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest * a point that is above the table, instead of returning -1 to * indicate that the hittest failed, a negative index is returned. * The fix is to consider any value that is negative a failure. */ OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo); if (pinfo.iItem < 0) pinfo.iItem = -1; } } if (pinfo.iItem != -1 && pinfo.iSubItem == 0) { if (hitTestSelection (pinfo.iItem, pinfo.x, pinfo.y)) { return _getItem (pinfo.iItem); } } return null; } } OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo); if (pinfo.iItem != -1) { /* * Bug in Windows. When the point that is used by * LVM_HITTEST is inside the header, Windows returns * the first item in the table. The fix is to check * when LVM_HITTEST returns the first item and make * sure that when the point is within the header, * the first item is not returned. */ if (pinfo.iItem == 0) { int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); if ((bits & OS.LVS_NOCOLUMNHEADER) == 0) { int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); if (hwndHeader != 0) { RECT rect = new RECT (); OS.GetWindowRect (hwndHeader, rect); POINT pt = new POINT (); pt.x = pinfo.x; pt.y = pinfo.y; OS.MapWindowPoints (handle, 0, pt, 1); if (OS.PtInRect (rect, pt)) return null; } } } return _getItem (pinfo.iItem); } return null; } /** * Returns the number of items contained in the receiver. * * @return the number of items * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int getItemCount () { checkWidget (); return (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); } /** * Returns the height of the area which would be used to * display one of the items in the receiver. * * @return the height of one item * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int getItemHeight () { checkWidget (); if (!painted && hooks (SWT.MeasureItem)) hitTestSelection (0, 0, 0); int /*long*/ empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0); int /*long*/ oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0); return OS.HIWORD (oneItem) - OS.HIWORD (empty); } /** * Returns a (possibly empty) array of TableItems which * are the items in the receiver. *

    * Note: This is not the actual structure used by the receiver * to maintain its list of items, so modifying the array will * not affect the receiver. *

    * * @return the items in the receiver * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public TableItem [] getItems () { checkWidget (); int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); TableItem [] result = new TableItem [count]; if ((style & SWT.VIRTUAL) != 0) { for (int i=0; itrue if the receiver's lines are visible, * and false otherwise. Note that some platforms draw * grid lines while others may draw alternating row colors. *

    * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, this method * may still indicate that it is considered visible even though * it may not actually be showing. *

    * * @return the visibility state of the lines * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public boolean getLinesVisible () { checkWidget (); int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); return (bits & OS.LVS_EX_GRIDLINES) != 0; } /** * Returns an array of TableItems that are currently * selected in the receiver. The order of the items is unspecified. * An empty array indicates that no items are selected. *

    * Note: This is not the actual structure used by the receiver * to maintain its selection, so modifying the array will * not affect the receiver. *

    * @return an array representing the selection * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public TableItem [] getSelection () { checkWidget (); int i = -1, j = 0, count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0); TableItem [] result = new TableItem [count]; while ((i = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i, OS.LVNI_SELECTED)) != -1) { result [j++] = _getItem (i); } return result; } /** * Returns the number of selected items contained in the receiver. * * @return the number of selected items * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int getSelectionCount () { checkWidget (); return (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0); } /** * Returns the zero-relative index of the item which is currently * selected in the receiver, or -1 if no item is selected. * * @return the index of the selected item * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int getSelectionIndex () { checkWidget (); int focusIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED); int selectedIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_SELECTED); if (focusIndex == selectedIndex) return selectedIndex; int i = -1; while ((i = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i, OS.LVNI_SELECTED)) != -1) { if (i == focusIndex) return i; } return selectedIndex; } /** * Returns the zero-relative indices of the items which are currently * selected in the receiver. The order of the indices is unspecified. * The array is empty if no items are selected. *

    * Note: This is not the actual structure used by the receiver * to maintain its selection, so modifying the array will * not affect the receiver. *

    * @return the array of indices of the selected items * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int [] getSelectionIndices () { checkWidget (); int i = -1, j = 0, count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0); int [] result = new int [count]; while ((i = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i, OS.LVNI_SELECTED)) != -1) { result [j++] = i; } return result; } /** * Returns the column which shows the sort indicator for * the receiver. The value may be null if no column shows * the sort indicator. * * @return the sort indicator * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see #setSortColumn(TableColumn) * * @since 3.2 */ public TableColumn getSortColumn () { checkWidget (); return sortColumn; } int getSortColumnPixel () { int pixel = OS.IsWindowEnabled (handle) ? getBackgroundPixel () : OS.GetSysColor (OS.COLOR_3DFACE); int red = pixel & 0xFF; int green = (pixel & 0xFF00) >> 8; int blue = (pixel & 0xFF0000) >> 16; if (red > 240 && green > 240 && blue > 240) { red -= 8; green -= 8; blue -= 8; } else { red = Math.min (0xFF, (red / 10) + red); green = Math.min (0xFF, (green / 10) + green); blue = Math.min (0xFF, (blue / 10) + blue); } return (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16); } /** * Returns the direction of the sort indicator for the receiver. * The value will be one of UP, DOWN * or NONE. * * @return the sort direction * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see #setSortDirection(int) * * @since 3.2 */ public int getSortDirection () { checkWidget (); return sortDirection; } /** * Returns the zero-relative index of the item which is currently * at the top of the receiver. This index can change when items are * scrolled or new items are added or removed. * * @return the index of the top item * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int getTopIndex () { checkWidget (); /* * Bug in Windows. Under rare circumstances, LVM_GETTOPINDEX * can return a negative number. When this happens, the table * is displaying blank lines at the top of the controls. The * fix is to check for a negative number and return zero instead. */ return Math.max (0, (int)/*64*/OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)); } boolean hasChildren () { int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); int /*long*/ hwndChild = OS.GetWindow (handle, OS.GW_CHILD); while (hwndChild != 0) { if (hwndChild != hwndHeader) return true; hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT); } return false; } boolean hitTestSelection (int index, int x, int y) { int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (count == 0) return false; if (!hooks (SWT.MeasureItem)) return false; boolean result = false; if (0 <= index && index < count) { TableItem item = _getItem (index); int /*long*/ hDC = OS.GetDC (handle); int /*long*/ oldFont = 0, newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont); int /*long*/ hFont = item.fontHandle (0); if (hFont != -1) hFont = OS.SelectObject (hDC, hFont); Event event = sendMeasureItemEvent (item, index, 0, hDC); if (event.getBounds ().contains (x, y)) result = true; if (hFont != -1) hFont = OS.SelectObject (hDC, hFont); if (newFont != 0) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); // if (isDisposed () || item.isDisposed ()) return false; } return result; } int imageIndex (Image image, int column) { if (image == null) return OS.I_IMAGENONE; if (column == 0) { firstColumnImage = true; } else { setSubImagesVisible (true); } if (imageList == null) { Rectangle bounds = image.getBounds (); imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height); int index = imageList.indexOf (image); if (index == -1) index = imageList.add (image); int /*long*/ hImageList = imageList.getHandle (); /* * Bug in Windows. Making any change to an item that * changes the item height of a table while the table * is scrolled can cause the lines to draw incorrectly. * This happens even when the lines are not currently * visible and are shown afterwards. The fix is to * save the top index, scroll to the top of the table * and then restore the original top index. */ int topIndex = getTopIndex (); if (topIndex != 0) { setRedraw (false); setTopIndex (0); } OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList); if (headerImageList != null) { int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); int /*long*/ hHeaderImageList = headerImageList.getHandle (); OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hHeaderImageList); } fixCheckboxImageList (false); setItemHeight (false); if (topIndex != 0) { setTopIndex (topIndex); setRedraw (true); } return index; } int index = imageList.indexOf (image); if (index != -1) return index; return imageList.add (image); } int imageIndexHeader (Image image) { if (image == null) return OS.I_IMAGENONE; if (headerImageList == null) { Rectangle bounds = image.getBounds (); headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height); int index = headerImageList.indexOf (image); if (index == -1) index = headerImageList.add (image); int /*long*/ hImageList = headerImageList.getHandle (); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hImageList); return index; } int index = headerImageList.indexOf (image); if (index != -1) return index; return headerImageList.add (image); } /** * Searches the receiver's list starting at the first column * (index 0) until a column is found that is equal to the * argument, and returns the index of that column. If no column * is found, returns -1. * * @param column the search column * @return the index of the column * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the column is null
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int indexOf (TableColumn column) { checkWidget (); if (column == null) error (SWT.ERROR_NULL_ARGUMENT); for (int i=0; i *
  • ERROR_NULL_ARGUMENT - if the item is null
  • * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public int indexOf (TableItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); //TODO - find other loops that can be optimized if (keys == null) { int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (1 <= lastIndexOf && lastIndexOf < count - 1) { if (_getItem (lastIndexOf, false) == item) return lastIndexOf; if (_getItem (lastIndexOf + 1, false) == item) return ++lastIndexOf; if (_getItem (lastIndexOf - 1, false) == item) return --lastIndexOf; } if (lastIndexOf < count / 2) { for (int i=0; i=0; --i) { if (_getItem (i, false) == item) return lastIndexOf = i; } } } else { for (int i=0; itrue if the item is selected, * and false otherwise. Indices out of * range are ignored. * * @param index the index of the item * @return the selection state of the item at the index * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public boolean isSelected (int index) { checkWidget (); LVITEM lvItem = new LVITEM (); lvItem.mask = OS.LVIF_STATE; lvItem.stateMask = OS.LVIS_SELECTED; lvItem.iItem = index; int /*long*/ result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem); return (result != 0) && ((lvItem.state & OS.LVIS_SELECTED) != 0); } void register () { super.register (); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); if (hwndHeader != 0) display.addControl (hwndHeader, this); } void releaseChildren (boolean destroy) { if (_hasItems ()) { int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); /* * Feature in Windows 98. When there are a large number * of columns and items in a table (>1000) where each * of the subitems in the table has a string, it is much * faster to delete each item with LVM_DELETEITEM rather * than using LVM_DELETEALLITEMS. The fix is to detect * this case and delete the items, one by one. The fact * that the fix is only necessary on Windows 98 was * confirmed using version 5.81 of COMCTL32.DLL on both * Windows 98 and NT. * * NOTE: LVM_DELETEALLITEMS is also sent by the table * when the table is destroyed. */ if (OS.IsWin95 && columnCount > 1) { /* Turn off redraw and resize events and leave them off */ resizeCount = 1; OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); for (int i=itemCount-1; i>=0; --i) { TableItem item = _getItem (i, false); if (item != null && !item.isDisposed ()) item.release (false); ignoreSelect = ignoreShrink = true; OS.SendMessage (handle, OS.LVM_DELETEITEM, i, 0); ignoreSelect = ignoreShrink = false; } } else { if (keys == null) { for (int i=0; i *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
  • *
  • ERROR_NULL_ARGUMENT - if the indices array is null
  • * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void remove (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); if (indices.length == 0) return; int [] newIndices = new int [indices.length]; System.arraycopy (indices, 0, newIndices, 0, indices.length); sort (newIndices); int start = newIndices [newIndices.length - 1], end = newIndices [0]; int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (!(0 <= start && start <= end && end < count)) { error (SWT.ERROR_INVALID_RANGE); } setDeferResize (true); int last = -1; for (int i=0; i *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
  • * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void remove (int index) { checkWidget (); int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE); TableItem item = _getItem (index, false); if (item != null && !item.isDisposed ()) item.release (false); setDeferResize (true); ignoreSelect = ignoreShrink = true; int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0); ignoreSelect = ignoreShrink = false; if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED); _removeItem (index, count); --count; if (count == 0) setTableEmpty (); setDeferResize (false); } /** * Removes the items from the receiver which are * between the given zero-relative start and end * indices (inclusive). * * @param start the start of the range * @param end the end of the range * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void remove (int start, int end) { checkWidget (); if (start > end) return; int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (!(0 <= start && start <= end && end < count)) { error (SWT.ERROR_INVALID_RANGE); } if (start == 0 && end == count - 1) { removeAll (); } else { setDeferResize (true); int index = start; while (index <= end) { TableItem item = _getItem (index, false); if (item != null && !item.isDisposed ()) item.release (false); ignoreSelect = ignoreShrink = true; int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, start, 0); ignoreSelect = ignoreShrink = false; if (code == 0) break; index++; } _removeItems (start, index, count); if (index <= end) error (SWT.ERROR_ITEM_NOT_REMOVED); /* * This code is intentionally commented. It is not necessary * to check for an empty table because removeAll() was called * when the start == 0 and end == count - 1. */ //if (count - index == 0) setTableEmpty (); setDeferResize (false); } } /** * Removes all of the items from the receiver. * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void removeAll () { checkWidget (); int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); for (int i=0; i1000) where each * of the subitems in the table has a string, it is much * faster to delete each item with LVM_DELETEITEM rather * than using LVM_DELETEALLITEMS. The fix is to detect * this case and delete the items, one by one. The fact * that the fix is only necessary on Windows 98 was * confirmed using version 5.81 of COMCTL32.DLL on both * Windows 98 and NT. * * NOTE: LVM_DELETEALLITEMS is also sent by the table * when the table is destroyed. */ setDeferResize (true); if (OS.IsWin95 && columnCount > 1) { boolean redraw = getDrawing () && OS.IsWindowVisible (handle); if (redraw) OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); int index = itemCount - 1; while (index >= 0) { ignoreSelect = ignoreShrink = true; int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0); ignoreSelect = ignoreShrink = false; if (code == 0) break; --index; } if (redraw) { OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); /* * This code is intentionally commented. The window proc * for the table implements WM_SETREDRAW to invalidate * and erase the table so it is not necessary to do this * again. */ // int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE; // OS.RedrawWindow (handle, null, 0, flags); } if (index != -1) error (SWT.ERROR_ITEM_NOT_REMOVED); } else { ignoreSelect = ignoreShrink = true; int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEALLITEMS, 0, 0); ignoreSelect = ignoreShrink = false; if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED); } setTableEmpty (); setDeferResize (false); } /** * Removes the listener from the collection of listeners who will * be notified when the user changes the receiver's selection. * * @param listener the listener which should no longer be notified * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see SelectionListener * @see #addSelectionListener(SelectionListener) */ public void removeSelectionListener(SelectionListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Selection, listener); eventTable.unhook (SWT.DefaultSelection,listener); } /** * Selects the items at the given zero-relative indices in the receiver. * The current selection is not cleared before the new items are selected. *

    * If the item at a given index is not selected, it is selected. * If the item at a given index was already selected, it remains selected. * Indices that are out of range and duplicate indices are ignored. * If the receiver is single-select and multiple indices are specified, * then all indices are ignored. *

    * * @param indices the array of indices for the items to select * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the array of indices is null
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#setSelection(int[]) */ public void select (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); int length = indices.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; LVITEM lvItem = new LVITEM (); lvItem.state = OS.LVIS_SELECTED; lvItem.stateMask = OS.LVIS_SELECTED; for (int i=length-1; i>=0; --i) { /* * An index of -1 will apply the change to all * items. Ensure that indices are greater than -1. */ if (indices [i] >= 0) { ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, indices [i], lvItem); ignoreSelect = false; } } } void reskinChildren (int flags) { if (_hasItems ()) { int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); for (int i=0; i *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ public void select (int index) { checkWidget (); /* * An index of -1 will apply the change to all * items. Ensure that index is greater than -1. */ if (index < 0) return; LVITEM lvItem = new LVITEM (); lvItem.state = OS.LVIS_SELECTED; lvItem.stateMask = OS.LVIS_SELECTED; ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem); ignoreSelect = false; } /** * Selects the items in the range specified by the given zero-relative * indices in the receiver. The range of indices is inclusive. * The current selection is not cleared before the new items are selected. *

    * If an item in the given range is not selected, it is selected. * If an item in the given range was already selected, it remains selected. * Indices that are out of range are ignored and no items will be selected * if start is greater than end. * If the receiver is single-select and there is more than one item in the * given range, then all indices are ignored. *

    * * @param start the start of the range * @param end the end of the range * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#setSelection(int,int) */ public void select (int start, int end) { checkWidget (); if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return; int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (count == 0 || start >= count) return; start = Math.max (0, start); end = Math.min (end, count - 1); if (start == 0 && end == count - 1) { selectAll (); } else { /* * An index of -1 will apply the change to all * items. Indices must be greater than -1. */ LVITEM lvItem = new LVITEM (); lvItem.state = OS.LVIS_SELECTED; lvItem.stateMask = OS.LVIS_SELECTED; for (int i=start; i<=end; i++) { ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, i, lvItem); ignoreSelect = false; } } } /** * Selects all of the items in the receiver. *

    * If the receiver is single-select, do nothing. *

    * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void selectAll () { checkWidget (); if ((style & SWT.SINGLE) != 0) return; LVITEM lvItem = new LVITEM (); lvItem.mask = OS.LVIF_STATE; lvItem.state = OS.LVIS_SELECTED; lvItem.stateMask = OS.LVIS_SELECTED; ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, -1, lvItem); ignoreSelect = false; } void sendEraseItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd, int /*long*/ lParam, Event measureEvent) { int /*long*/ hDC = nmcd.hdc; int clrText = item.cellForeground != null ? item.cellForeground [nmcd.iSubItem] : -1; if (clrText == -1) clrText = item.foreground; int clrTextBk = -1; if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { if (sortColumn != null && sortDirection != SWT.NONE) { if (findImageControl () == null) { if (indexOf (sortColumn) == nmcd.iSubItem) { clrTextBk = getSortColumnPixel (); } } } } 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 = (int)/*64*/nmcd.dwItemSpec; int /*long*/ 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, drawHot = false, drawDrophilited = false; if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) { drawHot = hotIndex == nmcd.dwItemSpec; drawDrophilited = (nmcd.uItemState & OS.CDIS_DROPHILITED) != 0; } if (OS.IsWindowEnabled (handle)) { if (selected && (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0)) { if (OS.GetFocus () == handle || display.getHighContrast ()) { 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); } if (explorerTheme) { data.foreground = clrText != -1 ? clrText : getForegroundPixel (); } } else { drawBackground = clrTextBk != -1; /* * Bug in Windows. When LVM_SETTEXTBKCOLOR, LVM_SETBKCOLOR * or LVM_SETTEXTCOLOR 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 color. */ if (clrText == -1 || clrTextBk == -1) { Control control = findBackgroundControl (); if (control == null) control = this; if (clrText == -1) clrText = control.getForegroundPixel (); if (clrTextBk == -1) 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.font = item.getFont (nmcd.iSubItem); data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); int nSavedDC = OS.SaveDC (hDC); GC gc = GC.win32_new (hDC, data); RECT cellRect = item.getBounds ((int)/*64*/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 (OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED) == nmcd.dwItemSpec) { if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) { if (handle == OS.GetFocus ()) { int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED; } } } boolean focused = (event.detail & SWT.FOCUSED) != 0; if (drawHot) event.detail |= SWT.HOT; 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 = data.foreground; 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; ignoreDrawFocus = (event.detail & SWT.FOCUSED) == 0; ignoreDrawHot = (event.detail & SWT.HOT) == 0; } else { ignoreDrawForeground = ignoreDrawBackground = ignoreDrawSelection = ignoreDrawFocus = ignoreDrawHot = true; } if (drawSelected) { if (ignoreDrawSelection) { ignoreDrawHot = true; if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) { selectionForeground = clrSelectionText; } nmcd.uItemState &= ~OS.CDIS_SELECTED; OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); } } else { if (ignoreDrawSelection) { nmcd.uItemState |= OS.CDIS_SELECTED; OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); } } int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); boolean firstColumn = nmcd.iSubItem == OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0); if (ignoreDrawForeground && ignoreDrawHot && !drawDrophilited) { if (!ignoreDrawBackground && drawBackground) { RECT backgroundRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, false, true, false, hDC); fillBackground (hDC, clrTextBk, backgroundRect); } } focusRect = null; if (!ignoreDrawHot || !ignoreDrawSelection || !ignoreDrawFocus || drawDrophilited) { boolean fullText = (style & SWT.FULL_SELECTION) != 0 || !firstColumn; RECT textRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, false, fullText, false, hDC); if ((style & SWT.FULL_SELECTION) == 0) { if (measureEvent != null) { textRect.right = Math.min (cellRect.right, measureEvent.x + measureEvent.width); } if (!ignoreDrawFocus) { nmcd.uItemState &= ~OS.CDIS_FOCUS; OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); focusRect = textRect; } } if (explorerTheme) { if (!ignoreDrawHot || drawDrophilited || (!ignoreDrawSelection && clrSelectionBk != -1)) { RECT pClipRect = new RECT (); OS.SetRect (pClipRect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); RECT rect = new RECT (); OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); if ((style & SWT.FULL_SELECTION) != 0) { int count = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0); int index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, count - 1, 0); RECT headerRect = new RECT (); OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect); OS.MapWindowPoints (hwndHeader, handle, headerRect, 2); rect.right = headerRect.right; index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0); OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect); OS.MapWindowPoints (hwndHeader, handle, headerRect, 2); rect.left = headerRect.left; pClipRect.left = cellRect.left; pClipRect.right += EXPLORER_EXTRA; } else { rect.right += EXPLORER_EXTRA; pClipRect.right += EXPLORER_EXTRA; } int /*long*/ hTheme = OS.OpenThemeData (handle, Display.LISTVIEW); int iStateId = selected ? OS.LISS_SELECTED : OS.LISS_HOT; if (OS.GetFocus () != handle && selected && !drawHot) iStateId = OS.LISS_SELECTEDNOTFOCUS; if (drawDrophilited) iStateId = OS.LISS_SELECTED; OS.DrawThemeBackground (hTheme, hDC, OS.LVP_LISTITEM, iStateId, rect, pClipRect); OS.CloseThemeData (hTheme); } } else { if (!ignoreDrawSelection && clrSelectionBk != -1) fillBackground (hDC, clrSelectionBk, textRect); } } if (focused && ignoreDrawFocus) { nmcd.uItemState &= ~OS.CDIS_FOCUS; OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); } if (ignoreDrawForeground) { RECT clipRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, true, true, false, hDC); OS.SaveDC (hDC); OS.SelectClipRgn (hDC, 0); OS.ExcludeClipRect (hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); } } Event sendEraseItemEvent (TableItem item, NMTTCUSTOMDRAW nmcd, int column, RECT cellRect) { int nSavedDC = OS.SaveDC (nmcd.hdc); RECT insetRect = toolTipInset (cellRect); OS.SetWindowOrgEx (nmcd.hdc, insetRect.left, insetRect.top, null); GCData data = new GCData (); data.device = display; data.foreground = OS.GetTextColor (nmcd.hdc); data.background = OS.GetBkColor (nmcd.hdc); data.font = item.getFont (column); data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); GC gc = GC.win32_new (nmcd.hdc, data); Event event = new Event (); event.item = item; event.index = column; event.gc = gc; event.detail |= SWT.FOREGROUND; 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 newTextClr = data.foreground; gc.dispose (); OS.RestoreDC (nmcd.hdc, nSavedDC); return event; } Event sendMeasureItemEvent (TableItem item, int row, int column, int /*long*/ hDC) { GCData data = new GCData (); data.device = display; data.font = item.getFont (column); int nSavedDC = OS.SaveDC (hDC); GC gc = GC.win32_new (hDC, data); RECT itemRect = item.getBounds (row, column, true, true, false, false, hDC); Event event = new Event (); event.item = item; event.gc = gc; event.index = column; event.x = itemRect.left; event.y = itemRect.top; event.width = itemRect.right - itemRect.left; event.height = itemRect.bottom - itemRect.top; boolean drawSelected = false; if (OS.IsWindowEnabled (handle)) { LVITEM lvItem = new LVITEM (); lvItem.mask = OS.LVIF_STATE; lvItem.stateMask = OS.LVIS_SELECTED; lvItem.iItem = (int)/*64*/row; int /*long*/ result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem); boolean selected = (result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0); if (selected && (column == 0 || (style & SWT.FULL_SELECTION) != 0)) { if (OS.GetFocus () == handle || display.getHighContrast ()) { drawSelected = true; } else { drawSelected = (style & SWT.HIDE_SELECTION) == 0; } } } if (drawSelected) event.detail |= SWT.SELECTED; sendEvent (SWT.MeasureItem, event); event.gc = null; gc.dispose (); OS.RestoreDC (hDC, nSavedDC); if (!isDisposed () && !item.isDisposed ()) { if (columnCount == 0) { int width = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0); if (event.x + event.width > width) setScrollWidth (event.x + event.width); } int /*long*/ empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0); int /*long*/ oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0); int itemHeight = OS.HIWORD (oneItem) - OS.HIWORD (empty); if (event.height > itemHeight) setItemHeight (event.height); } return event; } LRESULT sendMouseDownEvent (int type, int button, int msg, int /*long*/ wParam, int /*long*/ lParam) { Display display = this.display; display.captureChanged = false; if (!sendMouseEvent (type, button, handle, msg, wParam, lParam)) { if (!display.captureChanged && !isDisposed ()) { if (OS.GetCapture () != handle) OS.SetCapture (handle); } return LRESULT.ZERO; } /* * Feature in Windows. Inside WM_LBUTTONDOWN and WM_RBUTTONDOWN, * the widget starts a modal loop to determine if the user wants * to begin a drag/drop operation or marque select. Unfortunately, * this modal loop eats the corresponding mouse up. The fix is to * detect the cases when the modal loop has eaten the mouse up and * issue a fake mouse up. * * By observation, when the mouse is clicked anywhere but the check * box, the widget eats the mouse up. When the mouse is dragged, * the widget does not eat the mouse up. */ LVHITTESTINFO pinfo = new LVHITTESTINFO (); pinfo.x = OS.GET_X_LPARAM (lParam); pinfo.y = OS.GET_Y_LPARAM (lParam); OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo); if ((style & SWT.FULL_SELECTION) == 0) { if (hooks (SWT.MeasureItem)) { /* * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest * a point that is above the table, instead of returning -1 to * indicate that the hittest failed, a negative index is returned. * The fix is to consider any value that is negative a failure. */ if (OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo) < 0) { int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (count != 0) { RECT rect = new RECT (); rect.left = OS.LVIR_ICON; ignoreCustomDraw = true; int /*long*/ code = OS.SendMessage (handle, OS.LVM_GETITEMRECT, 0, rect); ignoreCustomDraw = false; if (code != 0) { pinfo.x = rect.left; /* * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest * a point that is above the table, instead of returning -1 to * indicate that the hittest failed, a negative index is returned. * The fix is to consider any value that is negative a failure. */ OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo); if (pinfo.iItem < 0) pinfo.iItem = -1; pinfo.flags &= ~(OS.LVHT_ONITEMICON | OS.LVHT_ONITEMLABEL); } } } else { if (pinfo.iSubItem != 0) pinfo.iItem = -1; } } } /* * Force the table to have focus so that when the user * reselects the focus item, the LVIS_FOCUSED state bits * for the item will be set. If the user did not click on * an item, then set focus to the table so that it will * come to the front and take focus in the work around * below. */ OS.SetFocus (handle); /* * Feature in Windows. When the user selects outside of * a table item, Windows deselects all the items, even * when the table is multi-select. While not strictly * wrong, this is unexpected. The fix is to detect the * case and avoid calling the window proc. */ if ((style & SWT.SINGLE) != 0 || hooks (SWT.MouseDown) || hooks (SWT.MouseUp)) { if (pinfo.iItem == -1) { if (!display.captureChanged && !isDisposed ()) { if (OS.GetCapture () != handle) OS.SetCapture (handle); } return LRESULT.ZERO; } } /* * Feature in Windows. When a table item is reselected * in a single-select table, Windows does not issue a * WM_NOTIFY because the item state has not changed. * This is strictly correct but is inconsistent with the * list widget and other widgets in Windows. The fix is * to detect the case when an item is reselected and mark * it as selected. */ boolean forceSelect = false; int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0); if (count == 1 && pinfo.iItem != -1) { LVITEM lvItem = new LVITEM (); lvItem.mask = OS.LVIF_STATE; lvItem.stateMask = OS.LVIS_SELECTED; lvItem.iItem = pinfo.iItem; OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem); if ((lvItem.state & OS.LVIS_SELECTED) != 0) { forceSelect = true; } } /* Determine whether the user has selected an item based on SWT.MeasureItem */ fullRowSelect = false; if (pinfo.iItem != -1) { if ((style & SWT.FULL_SELECTION) == 0) { if (hooks (SWT.MeasureItem)) { fullRowSelect = hitTestSelection (pinfo.iItem, pinfo.x, pinfo.y); if (fullRowSelect) { int flags = OS.LVHT_ONITEMICON | OS.LVHT_ONITEMLABEL; if ((pinfo.flags & flags) != 0) fullRowSelect = false; } } } } /* * Feature in Windows. Inside WM_LBUTTONDOWN and WM_RBUTTONDOWN, * the widget starts a modal loop to determine if the user wants * to begin a drag/drop operation or marque select. This modal * loop eats mouse events until a drag is detected. The fix is * to avoid this behavior by only running the drag and drop when * the event is hooked and the mouse is over an item. */ boolean dragDetect = (state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect); if (!dragDetect) { int flags = OS.LVHT_ONITEMICON | OS.LVHT_ONITEMLABEL; dragDetect = pinfo.iItem == -1 || (pinfo.flags & flags) == 0; if (fullRowSelect) dragDetect = true; } /* * Temporarily set LVS_EX_FULLROWSELECT to allow drag and drop * and the mouse to manipulate items based on the results of * the SWT.MeasureItem event. */ if (fullRowSelect) { OS.UpdateWindow (handle); OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_FULLROWSELECT, OS.LVS_EX_FULLROWSELECT); } dragStarted = false; display.dragCancelled = false; if (!dragDetect) display.runDragDrop = false; int /*long*/ code = callWindowProc (handle, msg, wParam, lParam, forceSelect); if (!dragDetect) display.runDragDrop = true; if (fullRowSelect) { fullRowSelect = false; OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_FULLROWSELECT, 0); } if (dragStarted || display.dragCancelled) { if (!display.captureChanged && !isDisposed ()) { if (OS.GetCapture () != handle) OS.SetCapture (handle); } } else { int flags = OS.LVHT_ONITEMLABEL | OS.LVHT_ONITEMICON; boolean fakeMouseUp = (pinfo.flags & flags) != 0; if (!fakeMouseUp && (style & SWT.MULTI) != 0) { fakeMouseUp = (pinfo.flags & OS.LVHT_ONITEMSTATEICON) == 0; } if (fakeMouseUp) { sendMouseEvent (SWT.MouseUp, button, handle, msg, wParam, lParam); } } return new LRESULT (code); } void sendPaintItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd) { int /*long*/ hDC = nmcd.hdc; GCData data = new GCData (); data.device = display; data.font = item.getFont (nmcd.iSubItem); /* * 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 = (int)/*64*/nmcd.dwItemSpec; int /*long*/ result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem); boolean selected = result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0; boolean drawSelected = false, drawBackground = false, drawHot = false; if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) { drawHot = hotIndex == nmcd.dwItemSpec; } if (OS.IsWindowEnabled (handle)) { if (selected && (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0)) { if (OS.GetFocus () == handle || display.getHighContrast ()) { drawSelected = true; if (selectionForeground != -1) { data.foreground = selectionForeground; } else { data.foreground = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT); } data.background = OS.GetSysColor (OS.COLOR_HIGHLIGHT); } else { drawSelected = (style & SWT.HIDE_SELECTION) == 0; data.foreground = OS.GetTextColor (hDC); data.background = OS.GetSysColor (OS.COLOR_3DFACE); } if (explorerTheme && selectionForeground == -1) { int clrText = item.cellForeground != null ? item.cellForeground [nmcd.iSubItem] : -1; if (clrText == -1) clrText = item.foreground; data.foreground = clrText != -1 ? clrText : getForegroundPixel (); } } else { 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; drawBackground = clrTextBk != -1; /* * Bug in Windows. When LVM_SETTEXTBKCOLOR, LVM_SETBKCOLOR * or LVM_SETTEXTCOLOR 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 color. */ if (clrText == -1 || clrTextBk == -1) { Control control = findBackgroundControl (); if (control == null) control = this; if (clrText == -1) clrText = control.getForegroundPixel (); if (clrTextBk == -1) 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); } data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); int nSavedDC = OS.SaveDC (hDC); GC gc = GC.win32_new (hDC, data); RECT itemRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, true, false, false, 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 (OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED) == nmcd.dwItemSpec) { if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) { if (handle == OS.GetFocus ()) { int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED; } } } if (drawHot) event.detail |= SWT.HOT; if (drawSelected) event.detail |= SWT.SELECTED; if (drawBackground) event.detail |= SWT.BACKGROUND; event.x = itemRect.left; event.y = itemRect.top; event.width = itemRect.right - itemRect.left; event.height = itemRect.bottom - itemRect.top; RECT cellRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, true, true, true, hDC); int cellWidth = cellRect.right - cellRect.left; int cellHeight = cellRect.bottom - cellRect.top; gc.setClipping (cellRect.left, cellRect.top, cellWidth, cellHeight); sendEvent (SWT.PaintItem, event); if (data.focusDrawn) focusRect = null; event.gc = null; gc.dispose (); OS.RestoreDC (hDC, nSavedDC); } Event sendPaintItemEvent (TableItem item, NMTTCUSTOMDRAW nmcd, int column, RECT itemRect) { int nSavedDC = OS.SaveDC (nmcd.hdc); RECT insetRect = toolTipInset (itemRect); OS.SetWindowOrgEx (nmcd.hdc, insetRect.left, insetRect.top, null); GCData data = new GCData (); data.device = display; data.font = item.getFont (column); data.foreground = OS.GetTextColor (nmcd.hdc); data.background = OS.GetBkColor (nmcd.hdc); data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); GC gc = GC.win32_new (nmcd.hdc, data); Event event = new Event (); event.item = item; event.index = column; event.gc = gc; event.detail |= SWT.FOREGROUND; event.x = itemRect.left; event.y = itemRect.top; event.width = itemRect.right - itemRect.left; event.height = itemRect.bottom - itemRect.top; //gc.setClipping (cellRect.left, cellRect.top, cellWidth, cellHeight); sendEvent (SWT.PaintItem, event); event.gc = null; gc.dispose (); OS.RestoreDC (nmcd.hdc, nSavedDC); return event; } void setBackgroundImage (int /*long*/ hBitmap) { super.setBackgroundImage (hBitmap); if (hBitmap != 0) { setBackgroundTransparent (true); } else { if (!hooks (SWT.MeasureItem) && !hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) { setBackgroundTransparent (false); } } } void setBackgroundPixel (int newPixel) { int oldPixel = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0); if (oldPixel != OS.CLR_NONE) { if (findImageControl () != null) return; if (newPixel == -1) newPixel = defaultBackground (); if (oldPixel != newPixel) { OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, newPixel); OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, newPixel); if ((style & SWT.CHECK) != 0) fixCheckboxImageListColor (true); } } /* * Feature in Windows. When the background color is changed, * the table does not redraw until the next WM_PAINT. The fix * is to force a redraw. */ OS.InvalidateRect (handle, null, true); } void setBackgroundTransparent (boolean transparent) { /* * Bug in Windows. When the table has the extended style * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with * CLR_NONE to make the table transparent, Windows draws * a black rectangle around the first column. The fix is * clear LVS_EX_FULLROWSELECT. * * Feature in Windows. When LVM_SETBKCOLOR is used with * CLR_NONE and LVM_SETSELECTEDCOLUMN is used to select * a column, Windows fills the column with the selection * color, drawing on top of the background image and any * other custom drawing. The fix is to clear the selected * column. */ int oldPixel = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0); if (transparent) { if (oldPixel != OS.CLR_NONE) { /* * Bug in Windows. When the background color is changed, * the table does not redraw until the next WM_PAINT. The * fix is to force a redraw. */ OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, OS.CLR_NONE); OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, OS.CLR_NONE); OS.InvalidateRect (handle, null, true); /* Clear LVS_EX_FULLROWSELECT */ if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) { int bits = OS.LVS_EX_FULLROWSELECT; OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, 0); } /* Clear LVM_SETSELECTEDCOLUMN */ if ((sortDirection & (SWT.UP | SWT.DOWN)) != 0) { if (sortColumn != null && !sortColumn.isDisposed ()) { OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, -1, 0); /* * Bug in Windows. When LVM_SETSELECTEDCOLUMN is set, Windows * does not redraw either the new or the previous selected column. * The fix is to force a redraw. */ OS.InvalidateRect (handle, null, true); } } } } else { if (oldPixel == OS.CLR_NONE) { Control control = findBackgroundControl (); if (control == null) control = this; if (control.backgroundImage == null) { int newPixel = control.getBackgroundPixel (); OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, newPixel); OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, newPixel); if ((style & SWT.CHECK) != 0) fixCheckboxImageListColor (true); OS.InvalidateRect (handle, null, true); } /* Set LVS_EX_FULLROWSELECT */ if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) { if (!hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) { int bits = OS.LVS_EX_FULLROWSELECT; OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits); } } /* Set LVM_SETSELECTEDCOLUMN */ if ((sortDirection & (SWT.UP | SWT.DOWN)) != 0) { if (sortColumn != null && !sortColumn.isDisposed ()) { int column = indexOf (sortColumn); if (column != -1) { OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, column, 0); /* * Bug in Windows. When LVM_SETSELECTEDCOLUMN is set, Windows * does not redraw either the new or the previous selected column. * The fix is to force a redraw. */ OS.InvalidateRect (handle, null, true); } } } } } } void setBounds (int x, int y, int width, int height, int flags, boolean defer) { /* * Bug in Windows. If the table column widths are adjusted * in WM_SIZE or WM_POSITIONCHANGED using LVM_SETCOLUMNWIDTH * blank lines may be inserted at the top of the table. A * call to LVM_GETTOPINDEX will return a negative number (this * is an impossible result). Once the blank lines appear, * there seems to be no way to get rid of them, other than * destroying and recreating the table. The fix is to send * the resize notification after the size has been changed in * the operating system. * * NOTE: This does not fix the case when the user is resizing * columns dynamically. There is no fix for this case at this * time. */ setDeferResize (true); super.setBounds (x, y, width, height, flags, false); setDeferResize (false); } /** * Sets the order that the items in the receiver should * be displayed in to the given argument which is described * in terms of the zero-relative ordering of when the items * were added. * * @param order the new order to display the items * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the item order is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items
    • *
    * * @see Table#getColumnOrder() * @see TableColumn#getMoveable() * @see TableColumn#setMoveable(boolean) * @see SWT#Move * * @since 3.1 */ public void setColumnOrder (int [] order) { checkWidget (); if (order == null) error (SWT.ERROR_NULL_ARGUMENT); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); if (columnCount == 0) { if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT); return; } if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT); int [] oldOrder = new int [columnCount]; OS.SendMessage (handle, OS.LVM_GETCOLUMNORDERARRAY, columnCount, oldOrder); boolean reorder = false; boolean [] seen = new boolean [columnCount]; for (int i=0; i= columnCount) error (SWT.ERROR_INVALID_RANGE); if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT); seen [index] = true; if (index != oldOrder [i]) reorder = true; } if (reorder) { RECT [] oldRects = new RECT [columnCount]; for (int i=0; i= 6 && OS.IsAppThemed ()) { Control control = findBackgroundControl (); if (control == null) control = this; clrBackground = control.getBackgroundPixel (); } else { clrBackground = 0x020000FF; if ((clrBackground & 0xFFFFFF) == OS.GetSysColor (OS.COLOR_WINDOW)) { clrBackground = 0x0200FF00; } } int /*long*/ hBrush = OS.CreateSolidBrush (clrBackground); OS.FillRect (memDC, rect, hBrush); OS.DeleteObject (hBrush); int /*long*/ oldFont = OS.SelectObject (hDC, defaultFont ()); TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA (); OS.GetTextMetrics (hDC, tm); OS.SelectObject (hDC, oldFont); int itemWidth = Math.min (tm.tmHeight, width); int itemHeight = Math.min (tm.tmHeight, height); int left = (width - itemWidth) / 2, top = (height - itemHeight) / 2 + 1; OS.SetRect (rect, left, top, left + itemWidth, top + itemHeight); if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { int /*long*/ hTheme = display.hButtonTheme (); OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, rect, null); rect.left += width; rect.right += width; OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_CHECKEDNORMAL, rect, null); rect.left += width; rect.right += width; OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, rect, null); rect.left += width; rect.right += width; OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_MIXEDNORMAL, rect, null); rect.left += width; rect.right += width; OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDDISABLED, rect, null); rect.left += width; rect.right += width; OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_CHECKEDDISABLED, rect, null); rect.left += width; rect.right += width; OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDDISABLED, rect, null); rect.left += width; rect.right += width; OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_MIXEDDISABLED, rect, null); } else { OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_FLAT); rect.left += width; rect.right += width; OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_FLAT); rect.left += width; rect.right += width; OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_INACTIVE | OS.DFCS_FLAT); rect.left += width; rect.right += width; OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_INACTIVE | OS.DFCS_FLAT); rect.left += width; rect.right += width; OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_FLAT); rect.left += width; rect.right += width; OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_FLAT); rect.left += width; rect.right += width; OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_INACTIVE | OS.DFCS_FLAT); rect.left += width; rect.right += width; OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_INACTIVE | OS.DFCS_FLAT); } OS.SelectObject (memDC, hOldBitmap); OS.DeleteDC (memDC); OS.ReleaseDC (handle, hDC); if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { OS.ImageList_Add (hStateList, hBitmap, 0); } else { OS.ImageList_AddMasked (hStateList, hBitmap, clrBackground); } OS.DeleteObject (hBitmap); /* * Bug in Windows. Making any change to an item that * changes the item height of a table while the table * is scrolled can cause the lines to draw incorrectly. * This happens even when the lines are not currently * visible and are shown afterwards. The fix is to * save the top index, scroll to the top of the table * and then restore the original top index. */ int topIndex = getTopIndex (); if (fixScroll && topIndex != 0) { setRedraw (false); setTopIndex (0); } int /*long*/ hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0); OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_STATE, hStateList); if (hOldStateList != 0) OS.ImageList_Destroy (hOldStateList); /* * Bug in Windows. Setting the LVSIL_STATE state image list * when the table already has a LVSIL_SMALL image list causes * pixel corruption of the images. The fix is to reset the * LVSIL_SMALL image list. */ if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { int /*long*/ hImageList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0); OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList); } if (fixScroll && topIndex != 0) { setTopIndex (topIndex); setRedraw (true); } } void setFocusIndex (int index) { // checkWidget (); /* * An index of -1 will apply the change to all * items. Ensure that index is greater than -1. */ if (index < 0) return; LVITEM lvItem = new LVITEM (); lvItem.state = OS.LVIS_FOCUSED; lvItem.stateMask = OS.LVIS_FOCUSED; ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem); ignoreSelect = false; OS.SendMessage (handle, OS.LVM_SETSELECTIONMARK, 0, index); } public void setFont (Font font) { checkWidget (); /* * Bug in Windows. Making any change to an item that * changes the item height of a table while the table * is scrolled can cause the lines to draw incorrectly. * This happens even when the lines are not currently * visible and are shown afterwards. The fix is to * save the top index, scroll to the top of the table * and then restore the original top index. */ int topIndex = getTopIndex (); if (topIndex != 0) { setRedraw (false); setTopIndex (0); } if (itemHeight != -1) { int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); OS.SetWindowLong (handle, OS.GWL_STYLE, bits | OS.LVS_OWNERDRAWFIXED); } super.setFont (font); if (itemHeight != -1) { int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); OS.SetWindowLong (handle, OS.GWL_STYLE, bits & ~OS.LVS_OWNERDRAWFIXED); } setScrollWidth (null, true); if (topIndex != 0) { setTopIndex (topIndex); setRedraw (true); } /* * Bug in Windows. Setting the font will cause the table * to be redrawn but not the column headers. The fix is * to force a redraw of the column headers. */ int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); OS.InvalidateRect (hwndHeader, null, true); } void setForegroundPixel (int pixel) { /* * The Windows table control uses CLR_DEFAULT to indicate * that it is using the default foreground color. This * is undocumented. */ if (pixel == -1) pixel = OS.CLR_DEFAULT; OS.SendMessage (handle, OS.LVM_SETTEXTCOLOR, 0, pixel); /* * Feature in Windows. When the foreground color is * changed, the table does not redraw until the next * WM_PAINT. The fix is to force a redraw. */ OS.InvalidateRect (handle, null, true); } /** * Marks the receiver's header as visible if the argument is true, * and marks it invisible otherwise. *

    * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, marking * it visible may not actually cause it to be displayed. *

    * * @param show the new visibility state * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void setHeaderVisible (boolean show) { checkWidget (); int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE); newBits &= ~OS.LVS_NOCOLUMNHEADER; if (!show) newBits |= OS.LVS_NOCOLUMNHEADER; /* * Feature in Windows. Setting or clearing LVS_NOCOLUMNHEADER * causes the table to scroll to the beginning. The fix is to * save and restore the top index causing the table to scroll * to the new location. */ int oldIndex = getTopIndex (); OS.SetWindowLong (handle, OS.GWL_STYLE, newBits); /* * Bug in Windows. Making any change to an item that * changes the item height of a table while the table * is scrolled can cause the lines to draw incorrectly. * This happens even when the lines are not currently * visible and are shown afterwards. The fix is to * save the top index, scroll to the top of the table * and then restore the original top index. */ int newIndex = getTopIndex (); if (newIndex != 0) { setRedraw (false); setTopIndex (0); } if (show) { int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((bits & OS.LVS_EX_GRIDLINES) != 0) fixItemHeight (false); } setTopIndex (oldIndex); if (newIndex != 0) { setRedraw (true); } updateHeaderToolTips (); } /** * Sets the number of items contained in the receiver. * * @param count the number of items * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.0 */ public void setItemCount (int count) { checkWidget (); count = Math.max (0, count); int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (count == itemCount) return; setDeferResize (true); boolean isVirtual = (style & SWT.VIRTUAL) != 0; if (!isVirtual) setRedraw (false); int index = count; while (index < itemCount) { TableItem item = _getItem (index, false); if (item != null && !item.isDisposed ()) item.release (false); if (!isVirtual) { ignoreSelect = ignoreShrink = true; int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, count, 0); ignoreSelect = ignoreShrink = false; if (code == 0) break; } index++; } if (index < itemCount) error (SWT.ERROR_ITEM_NOT_REMOVED); _setItemCount (count, itemCount); if (isVirtual) { int flags = OS.LVSICF_NOINVALIDATEALL | OS.LVSICF_NOSCROLL; OS.SendMessage (handle, OS.LVM_SETITEMCOUNT, count, flags); /* * Bug in Windows. When a virtual table contains items and * LVM_SETITEMCOUNT is used to set the new item count to zero, * Windows does not redraw the table. Note that simply not * specifying LVSICF_NOINVALIDATEALL or LVSICF_NOSCROLL does * correct the problem. The fix is to force a redraw. */ if (count == 0 && itemCount != 0) { OS.InvalidateRect (handle, null, true); } } else { for (int i=itemCount; ione of the items in the table. * * @param itemHeight the height of one item * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ /*public*/ void setItemHeight (int itemHeight) { checkWidget (); if (itemHeight < -1) error (SWT.ERROR_INVALID_ARGUMENT); this.itemHeight = itemHeight; setItemHeight (true); setScrollWidth (null, true); } /** * Marks the receiver's lines as visible if the argument is true, * and marks it invisible otherwise. Note that some platforms draw grid lines * while others may draw alternating row colors. *

    * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, marking * it visible may not actually cause it to be displayed. *

    * * @param show the new visibility state * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void setLinesVisible (boolean show) { checkWidget (); int newBits = show ? OS.LVS_EX_GRIDLINES : 0; OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_GRIDLINES, newBits); if (show) { int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); if ((bits & OS.LVS_NOCOLUMNHEADER) == 0) fixItemHeight (true); } } public void setRedraw (boolean redraw) { checkWidget (); /* * Feature in Windows. When WM_SETREDRAW is used to turn * off drawing in a widget, it clears the WS_VISIBLE bits * and then sets them when redraw is turned back on. This * means that WM_SETREDRAW will make a widget unexpectedly * visible. The fix is to track the visibility state while * drawing is turned off and restore it when drawing is turned * back on. */ if (drawCount == 0) { int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); if ((bits & OS.WS_VISIBLE) == 0) state |= HIDDEN; } if (redraw) { if (--drawCount == 0) { /* * When many items are added to a table, it is faster to * temporarily unsubclass the window proc so that messages * are dispatched directly to the table. * * NOTE: This is optimization somewhat dangerous because any * operation can occur when redraw is turned off, even operations * where the table must be subclassed in order to have the correct * behavior or work around a Windows bug. * * This code is intentionally commented. */ // subclass (); /* Set the width of the horizontal scroll bar */ setScrollWidth (null, true); /* * Bug in Windows. For some reason, when WM_SETREDRAW is used * to turn redraw back on this may result in a WM_SIZE. If the * table column widths are adjusted in WM_SIZE, blank lines may * be inserted at the top of the widget. A call to LVM_GETTOPINDEX * will return a negative number (this is an impossible result). * The fix is to send the resize notification after the size has * been changed in the operating system. */ setDeferResize (true); OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); if (hwndHeader != 0) OS.SendMessage (hwndHeader, OS.WM_SETREDRAW, 1, 0); if ((state & HIDDEN) != 0) { state &= ~HIDDEN; OS.ShowWindow (handle, OS.SW_HIDE); } else { if (OS.IsWinCE) { OS.InvalidateRect (handle, null, false); if (hwndHeader != 0) { OS.InvalidateRect (hwndHeader, null, false); } } else { int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN; OS.RedrawWindow (handle, null, 0, flags); } } setDeferResize (false); } } else { if (drawCount++ == 0) { OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); if (hwndHeader != 0) OS.SendMessage (hwndHeader, OS.WM_SETREDRAW, 0, 0); /* * When many items are added to a table, it is faster to * temporarily unsubclass the window proc so that messages * are dispatched directly to the table. * * NOTE: This is optimization somewhat dangerous because any * operation can occur when redraw is turned off, even operations * where the table must be subclassed in order to have the correct * behavior or work around a Windows bug. * * This code is intentionally commented. */ // unsubclass (); } } } void setScrollWidth (int width) { if (width != (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0)) { /* * Feature in Windows. When LVM_SETCOLUMNWIDTH is sent, * Windows draws right away instead of queuing a WM_PAINT. * This can cause recursive calls when called from paint * or from messages that are retrieving the item data, * such as WM_NOTIFY, causing a stack overflow. The fix * is to turn off redraw and queue a repaint, collapsing * the recursive calls. */ boolean redraw = false; if (hooks (SWT.MeasureItem)) { redraw = getDrawing () && OS.IsWindowVisible (handle); } if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, width); if (redraw) { OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); if (OS.IsWinCE) { int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); if (hwndHeader != 0) OS.InvalidateRect (hwndHeader, null, true); OS.InvalidateRect (handle, null, true); } else { int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN; OS.RedrawWindow (handle, null, 0, flags); } } } } boolean setScrollWidth (TableItem item, boolean force) { if (currentItem != null) { if (currentItem != item) fixScrollWidth = true; return false; } if (!force && (!getDrawing () || !OS.IsWindowVisible (handle))) { fixScrollWidth = true; return false; } fixScrollWidth = false; /* * 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_SETCOLUMNWIDTH with LVSCW_AUTOSIZE. */ if (columnCount == 0) { int newWidth = 0, imageIndent = 0, index = 0; int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); while (index < itemCount) { String string = null; int /*long*/ hFont = -1; if (item != null) { string = item.text; imageIndent = Math.max (imageIndent, item.imageIndent); hFont = item.fontHandle (0); } else { TableItem tableItem = _getItem (index, false); if (tableItem != null) { string = tableItem.text; imageIndent = Math.max (imageIndent, tableItem.imageIndent); hFont = tableItem.fontHandle (0); } } if (string != null && string.length () != 0) { if (hFont != -1) { int /*long*/ hDC = OS.GetDC (handle); int /*long*/ oldFont = OS.SelectObject (hDC, hFont); int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; TCHAR buffer = new TCHAR (getCodePage (), string, false); RECT rect = new RECT (); OS.DrawText (hDC, buffer, buffer.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, (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSTRINGWIDTH, 0, buffer)); } } if (item != null) break; index++; } /* * Bug in Windows. When the width of the first column is * small but not zero, Windows draws '...' outside of the * bounds of the text. This is strange, but only causes * problems when the item is selected. In this case, Windows * clears the '...' but doesn't redraw it when the item is * deselected, causing pixel corruption. The fix is to ensure * that the column is at least wide enough to draw a single * space. */ if (newWidth == 0) { TCHAR buffer = new TCHAR (getCodePage (), " ", true); newWidth = Math.max (newWidth, (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSTRINGWIDTH, 0, buffer)); } int /*long*/ 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] + INSET; } int /*long*/ 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]; } else { /* * Bug in Windows. When LVM_SETIMAGELIST is used to remove the * image list by setting it to NULL, the item width and height * is not changed and space is reserved for icons despite the * fact that there are none. The fix is to set the image list * to be very small before setting it to NULL. This causes * Windows to reserve the smallest possible space when an image * list is removed. In this case, the scroll width must be one * pixel larger. */ newWidth++; } newWidth += INSET * 2; int oldWidth = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0); if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { newWidth += VISTA_EXTRA; } if (newWidth > oldWidth) { setScrollWidth (newWidth); return true; } } return false; } /** * Selects the items at the given zero-relative indices in the receiver. * The current selection is cleared before the new items are selected, * and if necessary the receiver is scrolled to make the new selection visible. *

    * Indices that are out of range and duplicate indices are ignored. * If the receiver is single-select and multiple indices are specified, * then all indices are ignored. *

    * * @param indices the indices of the items to select * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the array of indices is null
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#deselectAll() * @see Table#select(int[]) */ public void setSelection (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); deselectAll (); int length = indices.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; select (indices); int focusIndex = indices [0]; if (focusIndex != -1) setFocusIndex (focusIndex); showSelection (); } /** * Sets the receiver's selection to the given item. * The current selection is cleared before the new item is selected, * and if necessary the receiver is scrolled to make the new selection visible. *

    * If the item is not in the receiver, then it is ignored. *

    * * @param item the item to select * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the item is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ public void setSelection (TableItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); setSelection (new TableItem [] {item}); } /** * Sets the receiver's selection to be the given array of items. * The current selection is cleared before the new items are selected, * and if necessary the receiver is scrolled to make the new selection visible. *

    * Items that are not in the receiver are ignored. * If the receiver is single-select and multiple items are specified, * then all items are ignored. *

    * * @param items the array of items * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the array of items is null
    • *
    • ERROR_INVALID_ARGUMENT - if one of the items has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#deselectAll() * @see Table#select(int[]) * @see Table#setSelection(int[]) */ public void setSelection (TableItem [] items) { checkWidget (); if (items == null) error (SWT.ERROR_NULL_ARGUMENT); deselectAll (); int length = items.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; int focusIndex = -1; for (int i=length-1; i>=0; --i) { int index = indexOf (items [i]); if (index != -1) { select (focusIndex = index); } } if (focusIndex != -1) setFocusIndex (focusIndex); showSelection (); } /** * Selects the item at the given zero-relative index in the receiver. * The current selection is first cleared, then the new item is selected, * and if necessary the receiver is scrolled to make the new selection visible. * * @param index the index of the item to select * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#deselectAll() * @see Table#select(int) */ public void setSelection (int index) { checkWidget (); deselectAll (); select (index); if (index != -1) setFocusIndex (index); showSelection (); } /** * Selects the items in the range specified by the given zero-relative * indices in the receiver. The range of indices is inclusive. * The current selection is cleared before the new items are selected, * and if necessary the receiver is scrolled to make the new selection visible. *

    * Indices that are out of range are ignored and no items will be selected * if start is greater than end. * If the receiver is single-select and there is more than one item in the * given range, then all indices are ignored. *

    * * @param start the start index of the items to select * @param end the end index of the items to select * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#deselectAll() * @see Table#select(int,int) */ public void setSelection (int start, int end) { checkWidget (); deselectAll (); if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return; int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (count == 0 || start >= count) return; start = Math.max (0, start); end = Math.min (end, count - 1); select (start, end); setFocusIndex (start); showSelection (); } /** * Sets the column used by the sort indicator for the receiver. A null * value will clear the sort indicator. The current sort column is cleared * before the new column is set. * * @param column the column used by the sort indicator or null * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the column is disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ public void setSortColumn (TableColumn column) { checkWidget (); if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); if (sortColumn != null && !sortColumn.isDisposed ()) { sortColumn.setSortDirection (SWT.NONE); } sortColumn = column; if (sortColumn != null && sortDirection != SWT.NONE) { sortColumn.setSortDirection (sortDirection); } } /** * Sets the direction of the sort indicator for the receiver. The value * can be one of UP, DOWN or NONE. * * @param direction the direction of the sort indicator * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.2 */ public void setSortDirection (int direction) { checkWidget (); if ((direction & (SWT.UP | SWT.DOWN)) == 0 && direction != SWT.NONE) return; sortDirection = direction; if (sortColumn != null && !sortColumn.isDisposed ()) { sortColumn.setSortDirection (direction); } } void setSubImagesVisible (boolean visible) { int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((dwExStyle & OS.LVS_EX_SUBITEMIMAGES) != 0 == visible) return; int bits = visible ? OS.LVS_EX_SUBITEMIMAGES : 0; OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_SUBITEMIMAGES, bits); } void setTableEmpty () { if (imageList != null) { /* * Bug in Windows. When LVM_SETIMAGELIST is used to remove the * image list by setting it to NULL, the item width and height * is not changed and space is reserved for icons despite the * fact that there are none. The fix is to set the image list * to be very small before setting it to NULL. This causes * Windows to reserve the smallest possible space when an image * list is removed. */ int /*long*/ hImageList = OS.ImageList_Create (1, 1, 0, 0, 0); OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList); OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0); if (headerImageList != null) { int /*long*/ hHeaderImageList = headerImageList.getHandle (); int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hHeaderImageList); } OS.ImageList_Destroy (hImageList); display.releaseImageList (imageList); imageList = null; if (itemHeight != -1) setItemHeight (false); } if (!hooks (SWT.MeasureItem) && !hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) { Control control = findBackgroundControl (); if (control == null) control = this; if (control.backgroundImage == null) { setCustomDraw (false); setBackgroundTransparent (false); if (OS.COMCTL32_MAJOR < 6) style &= ~SWT.DOUBLE_BUFFERED; } } _initItems (); if (columnCount == 0) { OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, 0); setScrollWidth (null, false); } } /** * Sets the zero-relative index of the item which is currently * at the top of the receiver. This index can change when items * are scrolled or new items are added and removed. * * @param index the index of the top item * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    */ public void setTopIndex (int index) { checkWidget (); int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0); if (index == topIndex) return; if (!painted && hooks (SWT.MeasureItem)) hitTestSelection (index, 0, 0); /* * Bug in Windows. For some reason, LVM_SCROLL refuses to * scroll a table vertically when the width and height of * the table is smaller than a certain size. The values * that seem to cause the problem are width=68 and height=6 * but there is no guarantee that these values cause the * failure on different machines or on different versions * of Windows. It may depend on the font and any number * of other factors. For example, setting the font to * anything but the default sometimes fixes the problem. * The fix is to use LVM_GETCOUNTPERPAGE to detect the * case when the number of visible items is zero and * use LVM_ENSUREVISIBLE to scroll the table to make the * index visible. */ /* * Bug in Windows. When the table header is visible and * there is not enough space to show a single table item, * LVM_GETCOUNTPERPAGE can return a negative number instead * of zero. The fix is to test for negative or zero. */ if (OS.SendMessage (handle, OS.LVM_GETCOUNTPERPAGE, 0, 0) <= 0) { /* * Bug in Windows. For some reason, LVM_ENSUREVISIBLE can * scroll one item more or one item less when there is not * enough space to show a single table item. The fix is * to detect the case and call LVM_ENSUREVISIBLE again with * the same arguments. It seems that once LVM_ENSUREVISIBLE * has scrolled into the general area, it is able to scroll * to the exact item. */ OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1); if (index != OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)) { OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1); } return; } /* Use LVM_SCROLL to scroll the table */ RECT rect = new RECT (); rect.left = OS.LVIR_BOUNDS; ignoreCustomDraw = true; OS.SendMessage (handle, OS.LVM_GETITEMRECT, 0, rect); ignoreCustomDraw = false; int dy = (index - topIndex) * (rect.bottom - rect.top); OS.SendMessage (handle, OS.LVM_SCROLL, 0, dy); } /** * Shows the column. If the column is already showing in the receiver, * this method simply returns. Otherwise, the columns are scrolled until * the column is visible. * * @param column the column to be shown * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the column is null
    • *
    • ERROR_INVALID_ARGUMENT - if the column has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @since 3.0 */ public void showColumn (TableColumn column) { checkWidget (); if (column == null) error (SWT.ERROR_NULL_ARGUMENT); if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); if (column.parent != this) return; int index = indexOf (column); if (!(0 <= index && index < columnCount)) return; /* * Feature in Windows. Calling LVM_GETSUBITEMRECT with -1 for the * row number gives the bounds of the item that would be above the * first row in the table. This is undocumented and does not work * for the first column. In this case, to get the bounds of the * first column, get the bounds of the second column and subtract * the width of the first. The left edge of the second column is * also used as the right edge of the first. */ RECT itemRect = new RECT (); itemRect.left = OS.LVIR_BOUNDS; if (index == 0) { itemRect.top = 1; ignoreCustomDraw = true; OS.SendMessage (handle, OS.LVM_GETSUBITEMRECT, -1, itemRect); ignoreCustomDraw = false; itemRect.right = itemRect.left; int width = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0); itemRect.left = itemRect.right - width; } else { itemRect.top = index; ignoreCustomDraw = true; OS.SendMessage (handle, OS.LVM_GETSUBITEMRECT, -1, itemRect); ignoreCustomDraw = false; } /* * Bug in Windows. When a table that is drawing grid lines * is slowly scrolled horizontally to the left, the table does * not redraw the newly exposed vertical grid lines. The fix * is to save the old scroll position, call the window proc, * get the new scroll position and redraw the new area. */ int oldPos = 0; int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((bits & OS.LVS_EX_GRIDLINES) != 0) { SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS; OS.GetScrollInfo (handle, OS.SB_HORZ, info); oldPos = info.nPos; } RECT rect = new RECT (); OS.GetClientRect (handle, rect); if (itemRect.left < rect.left) { int dx = itemRect.left - rect.left; OS.SendMessage (handle, OS.LVM_SCROLL, dx, 0); } else { int width = Math.min (rect.right - rect.left, itemRect.right - itemRect.left); if (itemRect.left + width > rect.right) { int dx = itemRect.left + width - rect.right; OS.SendMessage (handle, OS.LVM_SCROLL, dx, 0); } } /* * Bug in Windows. When a table that is drawing grid lines * is slowly scrolled horizontally to the left, the table does * not redraw the newly exposed vertical grid lines. The fix * is to save the old scroll position, call the window proc, * get the new scroll position and redraw the new area. */ if ((bits & OS.LVS_EX_GRIDLINES) != 0) { SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS; OS.GetScrollInfo (handle, OS.SB_HORZ, info); int newPos = info.nPos; if (newPos < oldPos) { rect.right = oldPos - newPos + GRID_WIDTH; OS.InvalidateRect (handle, rect, true); } } } void showItem (int index) { if (!painted && hooks (SWT.MeasureItem)) hitTestSelection (index, 0, 0); /* * Bug in Windows. For some reason, when there is insufficient space * to show an item, LVM_ENSUREVISIBLE causes blank lines to be * inserted at the top of the widget. A call to LVM_GETTOPINDEX will * return a negative number (this is an impossible result). The fix * is to use LVM_GETCOUNTPERPAGE to detect the case when the number * of visible items is zero and use LVM_ENSUREVISIBLE with the * fPartialOK flag set to true to scroll the table. */ if (OS.SendMessage (handle, OS.LVM_GETCOUNTPERPAGE, 0, 0) <= 0) { /* * Bug in Windows. For some reason, LVM_ENSUREVISIBLE can * scroll one item more or one item less when there is not * enough space to show a single table item. The fix is * to detect the case and call LVM_ENSUREVISIBLE again with * the same arguments. It seems that once LVM_ENSUREVISIBLE * has scrolled into the general area, it is able to scroll * to the exact item. */ OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1); if (index != OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)) { OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1); } } else { OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 0); } } /** * Shows the item. If the item is already showing in the receiver, * this method simply returns. Otherwise, the items are scrolled until * the item is visible. * * @param item the item to be shown * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the item is null
    • *
    • ERROR_INVALID_ARGUMENT - if the item has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#showSelection() */ public void showItem (TableItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); int index = indexOf (item); if (index != -1) showItem (index); } /** * Shows the selection. If the selection is already showing in the receiver, * this method simply returns. Otherwise, the items are scrolled until * the selection is visible. * * @exception SWTException
      *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • *
    * * @see Table#showItem(TableItem) */ public void showSelection () { checkWidget (); int index = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_SELECTED); if (index != -1) showItem (index); } /*public*/ void sort () { checkWidget (); // if ((style & SWT.VIRTUAL) != 0) return; // int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); // if (itemCount == 0 || itemCount == 1) return; // Comparator comparator = new Comparator () { // int index = sortColumn == null ? 0 : indexOf (sortColumn); // public int compare (Object object1, Object object2) { // TableItem item1 = (TableItem) object1, item2 = (TableItem) object2; // if (sortDirection == SWT.UP || sortDirection == SWT.NONE) { // return item1.getText (index).compareTo (item2.getText (index)); // } else { // return item2.getText (index).compareTo (item1.getText (index)); // } // } // }; // Arrays.sort (items, 0, itemCount, comparator); // redraw (); } void subclass () { super.subclass (); if (HeaderProc != 0) { int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, display.windowProc); } } RECT toolTipInset (RECT rect) { if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { RECT insetRect = new RECT (); OS.SetRect (insetRect, rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1); return insetRect; } return rect; } RECT toolTipRect (RECT rect) { RECT toolRect = new RECT (); if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { OS.SetRect (toolRect, rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1); } else { int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0); OS.SetRect (toolRect, rect.left, rect.top, rect.right, rect.bottom); int dwStyle = OS.GetWindowLong (hwndToolTip, OS.GWL_STYLE); int dwExStyle = OS.GetWindowLong (hwndToolTip, OS.GWL_EXSTYLE); OS.AdjustWindowRectEx (toolRect, dwStyle, false, dwExStyle); } return toolRect; } String toolTipText (NMTTDISPINFO hdr) { int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0); if (hwndToolTip == hdr.hwndFrom && toolTipText != null) return ""; //$NON-NLS-1$ if (headerToolTipHandle == hdr.hwndFrom) { for (int i=0; i




    © 2015 - 2024 Weber Informatics LLC | Privacy Policy