blob: 196763b5a953195812f4f19751ceadb60f7186cc [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2007 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 org.eclipse.swt.internal.wpf.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* Instances of this class represent a selectable user interface object
* that represents an item in a table.
* <dl>
* <dt><b>Styles:</b></dt>
* <dd>(none)</dd>
* <dt><b>Events:</b></dt>
* <dd>(none)</dd>
* </dl>
* <p>
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
public class TableItem extends Item {
Table parent;
Image[] images;
int stringList, imageList, foregroundList, backgroundList, fontList, checkState;
boolean checked, grayed, cached, ignoreNotify;
// int imageIndent, background = -1, foreground = -1, font = -1;
// int [] cellBackground, cellForeground, cellFont;
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Table</code>) and a style value
* describing its behavior and appearance. The item is added
* to the end of the items maintained by its parent.
* <p>
* The style value is either one of the style constants defined in
* class <code>SWT</code> which is applicable to instances of this
* class, or must be built by <em>bitwise OR</em>'ing together
* (that is, using the <code>int</code> "|" operator) two or more
* of those <code>SWT</code> style constants. The class description
* lists the style constants that are applicable to the class.
* Style bits are also inherited from superclasses.
* </p>
*
* @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 <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
public TableItem (Table parent, int style) {
this (parent, style, -1);
}
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Table</code>), a style value
* describing its behavior and appearance, and the index
* at which to place it in the items maintained by its parent.
* <p>
* The style value is either one of the style constants defined in
* class <code>SWT</code> which is applicable to instances of this
* class, or must be built by <em>bitwise OR</em>'ing together
* (that is, using the <code>int</code> "|" operator) two or more
* of those <code>SWT</code> style constants. The class description
* lists the style constants that are applicable to the class.
* Style bits are also inherited from superclasses.
* </p>
*
* @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
* @param index the zero-relative index to store the receiver in its parent
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
* <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
public TableItem (Table parent, int style, int index) {
this (parent, style, index, 0);
}
TableItem (Table parent, int style, int index, int handle) {
super (parent, style);
this.parent = parent;
this.handle = handle;
if (handle == 0) {
parent.createItem (this, index);
} else {
createWidget ();
}
}
double computeWidth (int columnIndex) {
int rowPresenterType = OS.GridViewRowPresenter_typeid ();
int rowPresenter = findRowPresenter (handle, rowPresenterType);
double width = 0;
if (rowPresenter != 0) {
int contentPresenter = OS.VisualTreeHelper_GetChild (rowPresenter, columnIndex);
/*
* Bug in WPF. The DesiredSize property of the content presenter is always 0
* for all columns except the first column. The work around is to Measure the
* content presenter before asking for its DesiredSize. Calling Measure on the
* first column does not work because it will set DesiredSize to be equal to the
* available size you pass into the Measure function.
*/
if (columnIndex != 0) {
int availSize = OS.gcnew_Size (0x7FFFFFFF,0x7FFFFFFF);
OS.UIElement_Measure (contentPresenter, availSize);
OS.GCHandle_Free (availSize);
}
int size = OS.UIElement_DesiredSize (contentPresenter);
width = OS.Size_Width (size);
OS.GCHandle_Free (size);
OS.GCHandle_Free (contentPresenter);
OS.GCHandle_Free (rowPresenter);
}
OS.GCHandle_Free (rowPresenterType);
return width;
}
protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}
void columnAdded (int index) {
int newLength = parent.columnCount + 1;
if (images != null) {
Image [] temp = new Image [newLength];
System.arraycopy (images, 0, temp, 0, index);
System.arraycopy (images, index, temp, index + 1, parent.columnCount - index);
images = temp;
}
OS.ArrayList_Insert (stringList, index, 0);
OS.ArrayList_Insert (imageList, index, 0);
}
void columnRemoved (int index) {
if (images != null) {
Image [] temp = new Image [parent.columnCount];
System.arraycopy (images, 0, temp, 0, index);
System.arraycopy (images, index + 1, temp, index, parent.columnCount - index);
images = temp;
}
OS.ArrayList_RemoveAt (stringList, index);
OS.ArrayList_RemoveAt (imageList, index);
}
void createHandle () {
if (handle == 0) {
handle = OS.gcnew_ListViewItem ();
if (handle == 0) error (SWT.ERROR_NO_HANDLES);
int row = OS.gcnew_SWTRow (parent.jniRef, handle);
OS.ContentControl_Content (handle, row);
OS.GCHandle_Free (row);
}
OS.Control_HorizontalContentAlignment (handle, OS.HorizontalAlignment_Stretch);
OS.Control_VerticalContentAlignment (handle, OS.VerticalAlignment_Stretch);
updateCheckState (false);
}
void clear () {
if (imageList != 0) OS.GCHandle_Free (imageList);
imageList = 0;
images = null;
if (stringList != 0) OS.GCHandle_Free (stringList);
stringList = 0;
checked = grayed = false;
updateCheckState (false);
// background = foreground = font = -1;
// cellBackground = cellForeground = cellFont = null;
if ((parent.style & SWT.VIRTUAL) != 0) cached = false;
if (ignoreNotify) return;
int row = OS.ContentControl_Content (handle);
OS.SWTRow_NotifyPropertyChanged (row, Table.TEXT_NOTIFY);
OS.SWTRow_NotifyPropertyChanged (row, Table.IMAGE_NOTIFY);
OS.GCHandle_Free (row);
}
void deregister () {
display.removeWidget (handle);
}
void destroyWidget () {
parent.destroyItem (this);
releaseHandle ();
}
int findRowPresenter (int current, int rowPresenterType) {
int type = OS.Object_GetType (current);
boolean found = OS.Object_Equals (rowPresenterType, type);
OS.GCHandle_Free (type);
if (found) return current;
int childCount = OS.VisualTreeHelper_GetChildrenCount (current);
for (int i = 0; i < childCount; i++) {
int child = OS.VisualTreeHelper_GetChild (current, i);
int result = findRowPresenter (child, rowPresenterType);
if (child != result) OS.GCHandle_Free (child);
if (result != 0) return result;
}
return 0;
}
int findPart (int column, String partName) {
if (!OS.FrameworkElement_IsLoaded (handle)) updateLayout (handle);
if (!OS.FrameworkElement_IsLoaded (handle)) return 0;
int rowPresenterType = OS.GridViewRowPresenter_typeid ();
int rowPresenter = findRowPresenter (handle, rowPresenterType);
int contentPresenter = OS.VisualTreeHelper_GetChild (rowPresenter, column);
int columns = OS.GridView_Columns (parent.gridViewHandle);
int columnHandle = OS.GridViewColumnCollection_default (columns, column);
int cellTemplate = OS.GridViewColumn_CellTemplate (columnHandle);
int name = createDotNetString (partName, false);
int result = OS.FrameworkTemplate_FindName (cellTemplate, name, contentPresenter);
OS.GCHandle_Free (rowPresenterType);
OS.GCHandle_Free (rowPresenter);
OS.GCHandle_Free (contentPresenter);
OS.GCHandle_Free (columns);
OS.GCHandle_Free (columnHandle);
OS.GCHandle_Free (cellTemplate);
OS.GCHandle_Free (name);
return result;
}
/**
* Returns the receiver's background color.
*
* @return the background color
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 2.0
*/
public Color getBackground () {
checkWidget ();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
//TODO
return parent.getBackground();
// if (background == -1) return parent.getBackground ();
// return Color.win32_new (display, background);
}
/**
* Returns the background color at the given column index in the receiver.
*
* @param index the column index
* @return the background color
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public Color getBackground (int index) {
checkWidget ();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
int count = Math.max (1, parent.getColumnCount ());
if (0 > index || index > count - 1) return getBackground ();
//TODO
return parent.getBackground();
// int pixel = cellBackground != null ? cellBackground [index] : -1;
// return pixel == -1 ? getBackground () : Color.win32_new (display, pixel);
}
/**
* Returns a rectangle describing the receiver's size and location
* relative to its parent.
*
* @return the receiver's bounding rectangle
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.2
*/
public Rectangle getBounds () {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
int parentHandle = parent.topHandle ();
int point = OS.gcnew_Point (0, 0);
if (point == 0) error (SWT.ERROR_NO_HANDLES);
int location = OS.UIElement_TranslatePoint (handle, point, parentHandle);
int x = (int) OS.Point_X (location);
int y = (int) OS.Point_Y (location);
OS.GCHandle_Free (point);
OS.GCHandle_Free (location);
int width = (int) OS.FrameworkElement_ActualWidth (handle);
int height = (int) OS.FrameworkElement_ActualHeight (handle);
return new Rectangle (x, y, width, height);
}
/**
* Returns a rectangle describing the receiver's size and location
* relative to its parent at a column in the table.
*
* @param index the index that specifies the column
* @return the receiver's bounding column rectangle
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Rectangle getBounds (int index) {
checkWidget();
if (index != 0 && !parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
if (!(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
int rowPresenterType = OS.GridViewRowPresenter_typeid ();
int rowPresenter = findRowPresenter (handle, rowPresenterType);
int contentPresenter = OS.VisualTreeHelper_GetChild (rowPresenter, index);
int point = OS.gcnew_Point (0, 0);
if (point == 0) error (SWT.ERROR_NO_HANDLES);
int parentHandle = parent.topHandle ();
int location = OS.UIElement_TranslatePoint (contentPresenter, point, parentHandle);
int x = (int) OS.Point_X (location);
int y = (int) OS.Point_Y (location);
int width = (int) OS.FrameworkElement_ActualWidth (contentPresenter);
int height = (int) OS.FrameworkElement_ActualHeight (handle);
OS.GCHandle_Free (rowPresenter);
OS.GCHandle_Free (rowPresenterType);
OS.GCHandle_Free (point);
OS.GCHandle_Free (location);
OS.GCHandle_Free (contentPresenter);
return new Rectangle (x, y, width, height);
}
/**
* Returns <code>true</code> if the receiver is checked,
* and false otherwise. When the parent does not have
* the <code>CHECK</code> style, return false.
*
* @return the checked state of the checkbox
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean getChecked () {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
if ((parent.style & SWT.CHECK) == 0) return false;
return checked;
}
/**
* Returns the font that the receiver will use to paint textual information for this item.
*
* @return the receiver's font
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public Font getFont () {
checkWidget ();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
//TODO
return parent.getFont ();
// return font == -1 ? parent.getFont () : Font.win32_new (display, font);
}
/**
* Returns the font that the receiver will use to paint textual information
* for the specified cell in this item.
*
* @param index the column index
* @return the receiver's font
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public Font getFont (int index) {
checkWidget ();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
int count = Math.max (1, parent.getColumnCount ());
if (0 > index || index > count -1) return getFont ();
//TODO
return parent.getFont ();
// int hFont = (cellFont != null) ? cellFont [index] : font;
// return hFont == -1 ? getFont () : Font.win32_new (display, hFont);
}
/**
* Returns the foreground color that the receiver will use to draw.
*
* @return the receiver's foreground color
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 2.0
*/
public Color getForeground () {
checkWidget ();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
//TODO
return parent.getForeground ();
// if (foreground == -1) return parent.getForeground ();
// return Color.win32_new (display, foreground);
}
/**
*
* Returns the foreground color at the given column index in the receiver.
*
* @param index the column index
* @return the foreground color
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public Color getForeground (int index) {
checkWidget ();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
int count = Math.max (1, parent.getColumnCount ());
if (0 > index || index > count -1) return getForeground ();
//TODO
return parent.getForeground ();
// int pixel = cellForeground != null ? cellForeground [index] : -1;
// return pixel == -1 ? getForeground () : Color.win32_new (display, pixel);
}
/**
* Returns <code>true</code> if the receiver is grayed,
* and false otherwise. When the parent does not have
* the <code>CHECK</code> style, return false.
*
* @return the grayed state of the checkbox
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean getGrayed () {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
if ((parent.style & SWT.CHECK) == 0) return false;
return grayed;
}
public Image getImage () {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
return getImage (0);
}
/**
* Returns the image stored at the given column index in the receiver,
* or null if the image has not been set or if the column does not exist.
*
* @param index the column index
* @return the image stored at the given column index in the receiver
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Image getImage (int index) {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
if (images != null) {
if (0 <= index && index < images.length) return images [index];
}
return null;
}
/**
* Returns a rectangle describing the size and location
* relative to its parent of an image at a column in the
* table. An empty rectangle is returned if index exceeds
* the index of the table's last column.
*
* @param index the index that specifies the column
* @return the receiver's bounding image rectangle
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Rectangle getImageBounds (int index) {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
int parentHandle = parent.topHandle ();
int part = findPart (index, Table.IMAGE_PART_NAME);
int point = OS.gcnew_Point (0, 0);
if (point == 0) error (SWT.ERROR_NO_HANDLES);
int location = OS.UIElement_TranslatePoint (part, point, parentHandle);
int x = (int) OS.Point_X (location);
int y = (int) OS.Point_Y (location);
OS.GCHandle_Free (point);
OS.GCHandle_Free (location);
int width = (int) OS.FrameworkElement_ActualWidth (part);
int height = (int) OS.FrameworkElement_ActualHeight (part);
OS.GCHandle_Free (part);
return new Rectangle (x, y, width, height);
}
/**
* Gets the image indent.
*
* @return the indent
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int getImageIndent () {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
//TODO
return 0;
// return imageIndent;
}
String getNameText () {
if ((parent.style & SWT.VIRTUAL) != 0) {
if (!cached) return "*virtual*"; //$NON-NLS-1$
}
return super.getNameText ();
}
/**
* Returns the receiver's parent, which must be a <code>Table</code>.
*
* @return the receiver's parent
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Table getParent () {
checkWidget();
return parent;
}
/**
* Returns a rectangle describing the size and location
* relative to its parent of the text at a column in the
* table. An empty rectangle is returned if index exceeds
* the index of the table's last column.
*
* @param index the index that specifies the column
* @return the receiver's bounding text rectangle
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.3
*/
public Rectangle getTextBounds (int index) {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
int parentHandle = parent.topHandle ();
int part = findPart (index, Table.TEXT_PART_NAME);
int point = OS.gcnew_Point (0, 0);
if (point == 0) error (SWT.ERROR_NO_HANDLES);
int location = OS.UIElement_TranslatePoint (part, point, parentHandle);
int x = (int) OS.Point_X (location);
int y = (int) OS.Point_Y (location);
OS.GCHandle_Free (point);
OS.GCHandle_Free (location);
int width = (int) OS.FrameworkElement_ActualWidth (part);
int height = (int) OS.FrameworkElement_ActualHeight (part);
OS.GCHandle_Free (part);
return new Rectangle (x, y, width, height);
}
public String getText () {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
return getText (0);
}
/**
* Returns the text stored at the given column index in the receiver,
* or empty string if the text has not been set.
*
* @param index the column index
* @return the text stored at the given column index in the receiver
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public String getText (int index) {
checkWidget();
if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
if (stringList != 0) {
if (0 <= index && index < OS.ArrayList_Count (stringList)) {
int ptr = OS.ArrayList_default (stringList, index);
String result = createJavaString (ptr);
OS.GCHandle_Free (ptr);
return result;
}
}
return "";
}
Control getWidgetControl () {
return parent;
}
//void HandlePreviewGotKeyboardFocus (int sender, int e) {
//// if (!checkEvent (e)) return;
//// OS.RoutedEventArgs_Handled(e, true);
//}
//
//void HandleLostKeyboardFocus (int sender, int e) {
//// if (!checkEvent (e)) return;
//// OS.RoutedEventArgs_Handled(e, true);
//}
//
//void hookEvents () {
// int handler = OS.gcnew_KeyboardFocusChangedEventHandler (jniRef, "HandlePreviewGotKeyboardFocus");
// OS.UIElement_PreviewGotKeyboardFocus (handle, handler);
// OS.GCHandle_Free (handler);
// handler = OS.gcnew_KeyboardFocusChangedEventHandler (jniRef, "HandleLostKeyboardFocus");
// OS.UIElement_LostKeyboardFocus (handle, handler);
// OS.GCHandle_Free (handler);
//}
void register () {
display.addWidget (handle, this);
}
void releaseHandle () {
super.releaseHandle ();
if (handle != 0) OS.GCHandle_Free (handle);
handle = 0;
parent = null;
}
void releaseWidget () {
super.releaseWidget ();
if (imageList != 0) OS.GCHandle_Free (imageList);
imageList = 0;
if (stringList != 0) OS.GCHandle_Free (stringList);
stringList = 0;
if (checkState != 0) OS.GCHandle_Free (checkState);
checkState = 0;
}
/**
* Sets the receiver's background color to the color specified
* by the argument, or to the default system color for the item
* if the argument is null.
*
* @param color the new color (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 2.0
*/
public void setBackground (Color color) {
checkWidget ();
if (color != null && color.isDisposed ()) {
SWT.error (SWT.ERROR_INVALID_ARGUMENT);
}
// int pixel = -1;
//TODO
// if (color != null) {
// parent.setCustomDraw (true);
// pixel = color.handle;
// }
// if (background == pixel) return;
// background = pixel;
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
// redraw ();
}
/**
* Sets the background color at the given column index in the receiver
* to the color specified by the argument, or to the default system color for the item
* if the argument is null.
*
* @param index the column index
* @param color the new color (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public void setBackground (int index, Color color) {
checkWidget ();
if (color != null && color.isDisposed ()) {
SWT.error (SWT.ERROR_INVALID_ARGUMENT);
}
int count = Math.max (1, parent.getColumnCount ());
if (0 > index || index > count - 1) return;
// int pixel = -1;
//TODO
// if (color != null) {
// parent.setCustomDraw (true);
// pixel = color.handle;
// }
// if (cellBackground == null) {
// cellBackground = new int [count];
// for (int i = 0; i < count; i++) {
// cellBackground [i] = -1;
// }
// }
// if (cellBackground [index] == pixel) return;
// cellBackground [index] = pixel;
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
// redraw (index, true, true);
}
/**
* Sets the checked state of the checkbox for this item. This state change
* only applies if the Table was created with the SWT.CHECK style.
*
* @param checked the new checked state of the checkbox
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setChecked (boolean checked) {
checkWidget();
if ((parent.style & SWT.CHECK) == 0) return;
if (this.checked == checked) return;
this.checked = checked;
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
updateCheckState (true);
}
/**
* Sets the font that the receiver will use to paint textual information
* for this item to the font specified by the argument, or to the default font
* for that kind of control if the argument is null.
*
* @param font the new font (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public void setFont (Font font){
checkWidget ();
if (font != null && font.isDisposed ()) {
SWT.error (SWT.ERROR_INVALID_ARGUMENT);
}
// int hFont = -1;
// if (font != null) {
// parent.setCustomDraw (true);
// hFont = font.handle;
// }
// if (this.font == hFont) return;
// this.font = hFont;
if ((parent.style & SWT.VIRTUAL) != 0) cached = 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 ((parent.style & SWT.VIRTUAL) == 0 && cached) {
// int itemIndex = parent.indexOf (this);
// if (itemIndex != -1) {
// int hwnd = parent.handle;
// LVITEM lvItem = new LVITEM ();
// lvItem.mask = OS.LVIF_TEXT;
// lvItem.iItem = itemIndex;
// lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
// OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
// cached = false;
// }
// }
// parent.setScrollWidth (this, false);
// redraw ();
}
/**
* Sets the font that the receiver will use to paint textual information
* for the specified cell in this item to the font specified by the
* argument, or to the default font for that kind of control if the
* argument is null.
*
* @param index the column index
* @param font the new font (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public void setFont (int index, Font font) {
checkWidget ();
if (font != null && font.isDisposed ()) {
SWT.error (SWT.ERROR_INVALID_ARGUMENT);
}
int count = Math.max (1, parent.getColumnCount ());
if (0 > index || index > count - 1) return;
//TODO
// int hFont = -1;
// if (font != null) {
// parent.setCustomDraw (true);
// hFont = font.handle;
// }
// if (cellFont == null) {
// cellFont = new int [count];
// for (int i = 0; i < count; i++) {
// cellFont [i] = -1;
// }
// }
// if (cellFont [index] == hFont) return;
// cellFont [index] = hFont;
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
// if (index == 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 ((parent.style & SWT.VIRTUAL) == 0 && cached) {
// int itemIndex = parent.indexOf (this);
// if (itemIndex != -1) {
// int hwnd = parent.handle;
// LVITEM lvItem = new LVITEM ();
// lvItem.mask = OS.LVIF_TEXT;
// lvItem.iItem = itemIndex;
// lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
// OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
// cached = false;
// }
// }
// parent.setScrollWidth (this, false);
// }
// redraw (index, true, false);
}
/**
* Sets the receiver's foreground color to the color specified
* by the argument, or to the default system color for the item
* if the argument is null.
*
* @param color the new color (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 2.0
*/
public void setForeground (Color color){
checkWidget ();
if (color != null && color.isDisposed ()) {
SWT.error (SWT.ERROR_INVALID_ARGUMENT);
}
//TODO
// int pixel = -1;
// if (color != null) {
// parent.setCustomDraw (true);
// pixel = color.handle;
// }
// if (foreground == pixel) return;
// foreground = pixel;
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
// redraw ();
}
/**
* Sets the foreground color at the given column index in the receiver
* to the color specified by the argument, or to the default system color for the item
* if the argument is null.
*
* @param index the column index
* @param color the new color (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public void setForeground (int index, Color color){
checkWidget ();
if (color != null && color.isDisposed ()) {
SWT.error (SWT.ERROR_INVALID_ARGUMENT);
}
int count = Math.max (1, parent.getColumnCount ());
if (0 > index || index > count - 1) return;
//TODO
// int pixel = -1;
// if (color != null) {
// parent.setCustomDraw (true);
// pixel = color.handle;
// }
// if (cellForeground == null) {
// cellForeground = new int [count];
// for (int i = 0; i < count; i++) {
// cellForeground [i] = -1;
// }
// }
// if (cellForeground [index] == pixel) return;
// cellForeground [index] = pixel;
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
// redraw (index, true, false);
}
/**
* Sets the grayed state of the checkbox for this item. This state change
* only applies if the Table was created with the SWT.CHECK style.
*
* @param grayed the new grayed state of the checkbox;
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setGrayed (boolean grayed) {
checkWidget();
if ((parent.style & SWT.CHECK) == 0) return;
if (this.grayed == grayed) return;
this.grayed = grayed;
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
updateCheckState (true);
}
/**
* Sets the image for multiple columns in the table.
*
* @param images the array of new images
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
* <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setImage (Image [] images) {
checkWidget();
if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
for (int i=0; i<images.length; i++) {
setImage (i, images [i]);
}
}
/**
* Sets the receiver's image at a column.
*
* @param index the column index
* @param image the new image
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setImage (int index, Image image) {
checkWidget();
if (image != null && image.isDisposed ()) {
error(SWT.ERROR_INVALID_ARGUMENT);
}
int count = Math.max (1, parent.getColumnCount ());
if (0 > index || index > count - 1) return;
if (images == null) {
images = new Image [count];
}
images [index] = image;
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
if (imageList == 0) {
imageList = OS.gcnew_ArrayList (count);
for (int i = 0; i < count; i++) {
OS.ArrayList_Insert (imageList, i, 0);
}
}
int imageHandle = image != null ? image.handle : 0;
OS.ArrayList_default (imageList, index, imageHandle);
if (ignoreNotify) return;
int row = OS.ContentControl_Content (handle);
OS.SWTRow_NotifyPropertyChanged (row, Table.IMAGE_NOTIFY);
OS.GCHandle_Free (row);
}
public void setImage (Image image) {
checkWidget ();
setImage (0, image);
}
/**
* Sets the indent of the first column's image, expressed in terms of the image's width.
*
* @param indent the new indent
*
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @deprecated this functionality is not supported on most platforms
*/
public void setImageIndent (int indent) {
checkWidget();
}
/**
* Sets the text for multiple columns in the table.
*
* @param strings the array of new strings
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the text is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setText (String [] strings) {
checkWidget();
if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
for (int i=0; i<strings.length; i++) {
String string = strings [i];
if (string != null) setText (i, string);
}
}
/**
* Sets the receiver's text at a column
*
* @param index the column index
* @param string the new text
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the text is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setText (int index, String string) {
checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
int count = Math.max(1, parent.getColumnCount ());
if (0 > index || index > count - 1) return;
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
if (stringList == 0) {
stringList = OS.gcnew_ArrayList (count);
for (int i = 0; i < count; i++) {
OS.ArrayList_Insert (stringList, i, 0);
}
}
int str = createDotNetString (string, false);
OS.ArrayList_default (stringList, index, str);
OS.GCHandle_Free (str);
if (ignoreNotify) return;
int row = OS.ContentControl_Content (handle);
OS.SWTRow_NotifyPropertyChanged (row, Table.TEXT_NOTIFY);
OS.GCHandle_Free (row);
}
public void setText (String string) {
checkWidget();
setText (0, string);
}
void updateCheckState (boolean notify) {
if ((parent.style & SWT.CHECK) == 0) return;
if (checkState != 0) OS.GCHandle_Free (checkState);
if (checked) {
checkState = grayed ? OS.gcnew_IntPtr (2) : OS.gcnew_IntPtr (1);
} else {
checkState = OS.gcnew_IntPtr (0);
}
if (notify) {
int row = OS.ContentControl_Content (handle);
OS.SWTRow_NotifyPropertyChanged (row, Table.CHECK_NOTIFY);
OS.GCHandle_Free (row);
}
}
}