Mercurial > projects > dwt-addons
diff dwtx/jface/viewers/ViewerCell.d @ 70:46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 22 May 2008 01:36:46 +0200 |
parents | b6c35faf97c8 |
children | 5df4896124c7 |
line wrap: on
line diff
--- a/dwtx/jface/viewers/ViewerCell.d Mon May 19 13:41:06 2008 +0200 +++ b/dwtx/jface/viewers/ViewerCell.d Thu May 22 01:36:46 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2008 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 @@ -7,13 +7,15 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * - fix in bug: 195908,198035,215069,215735 * Port to the D programming language: * Frank Benoit <benoit@tionex.de> *******************************************************************************/ module dwtx.jface.viewers.ViewerCell; +import dwt.custom.StyleRange; import dwtx.jface.viewers.ViewerRow; import dwt.graphics.Color; @@ -59,6 +61,7 @@ */ public static int RIGHT = 1 << 3; + /** * Create a new instance of the receiver on the row. * @@ -98,7 +101,12 @@ if (element !is null) { return element; } - return row.getElement(); + + if (row !is null) { + return row.getElement(); + } + + return null; } /** @@ -168,6 +176,31 @@ row.setImage(columnIndex, image); } + + /** + * Set the style ranges to be applied on the text label + * Note: Requires {@link StyledCellLabelProvider} with owner draw enabled. + * + * @param styleRanges the styled ranges + * + * @since 3.4 + */ + public void setStyleRanges(StyleRange[] styleRanges) { + row.setStyleRanges(columnIndex, styleRanges); + } + + + /** + * Returns the style ranges to be applied on the text label or <code>null</code> if no + * style ranges have been set. + * + * @return styleRanges the styled ranges + * + * @since 3.4 + */ + public StyleRange[] getStyleRanges() { + return row.getStyleRanges(columnIndex); + } /** * Set the columnIndex. @@ -210,6 +243,17 @@ } /** + * Get the current index. This can be different from the original index when + * columns are reordered + * + * @return the current index (as shown in the UI) + * @since 3.4 + */ + public int getVisualIndex() { + return row.getVisualIndex(getColumnIndex()); + } + + /** * Returns the specified neighbor of this cell, or <code>null</code> if no * neighbor exists in the given direction. Direction constants can be * combined by bitwise OR; for example, this method will return the cell to @@ -226,7 +270,6 @@ */ public ViewerCell getNeighbor(int directionMask, bool sameLevel) { ViewerRow row; - int columnIndex; if ((directionMask & ABOVE) is ABOVE) { row = this.row.getNeighbor(ViewerRow.ABOVE, sameLevel); @@ -237,16 +280,36 @@ } if (row !is null) { + int columnIndex; + columnIndex = getVisualIndex(); + + int modifier = 0; + if ((directionMask & LEFT) is LEFT) { - columnIndex = getColumnIndex() - 1; + modifier = -1; } else if ((directionMask & RIGHT) is RIGHT) { - columnIndex = getColumnIndex() + 1; - } else { - columnIndex = getColumnIndex(); + modifier = 1; } + columnIndex += modifier; + if (columnIndex >= 0 && columnIndex < row.getColumnCount()) { - return row.getCell(columnIndex); + ViewerCell cell = row.getCellAtVisualIndex(columnIndex); + if( cell !is null ) { + while( cell !is null ) { + if( cell.isVisible() ) { + break; + } + + columnIndex += modifier; + cell = row.getCellAtVisualIndex(columnIndex); + if( cell is null ) { + break; + } + } + } + + return cell; } } @@ -260,7 +323,67 @@ return row; } - /* (non-Javadoc) + /** + * The location and bounds of the area where the text is drawn depends on + * various things (image displayed, control with DWT.CHECK) + * + * @return The bounds of the of the text area. May return <code>null</code> + * if the underlying widget implementation doesn't provide this + * information + * @since 3.4 + */ + public Rectangle getTextBounds() { + return row.getTextBounds(columnIndex); + } + + /** + * Returns the location and bounds of the area where the image is drawn + * + * @return The bounds of the of the image area. May return <code>null</code> + * if the underlying widget implementation doesn't provide this + * information + * @since 3.4 + */ + public Rectangle getImageBounds() { + return row.getImageBounds(columnIndex); + } + + /** + * Gets the foreground color of the cell. + * + * @return the foreground of the cell or <code>null</code> for the default foreground + * + * @since 3.4 + */ + public Color getForeground() { + return row.getForeground(columnIndex); + } + + /** + * Gets the background color of the cell. + * + * @return the background of the cell or <code>null</code> for the default background + * + * @since 3.4 + */ + public Color getBackground() { + return row.getBackground(columnIndex); + } + + /** + * Gets the font of the cell. + * + * @return the font of the cell or <code>null</code> for the default font + * + * @since 3.4 + */ + public Font getFont() { + return row.getFont(columnIndex); + } + + /* + * (non-Javadoc) + * * @see java.lang.Object#hashCode() */ public override hash_t toHash() { @@ -271,7 +394,9 @@ return result; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#equals(java.lang.Object) */ public override int opEquals(Object obj) { @@ -291,4 +416,8 @@ return false; return true; } + + private bool isVisible() { + return getBounds().width > 0; + } }