Mercurial > projects > dwt-addons
view dwtx/ui/internal/forms/widgets/ObjectSegment.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 26c6c9dfd13c |
children |
line wrap: on
line source
/******************************************************************************* * 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 * Port to the D programming language: * Frank Benoit <benoit@tionex.de> *******************************************************************************/ module dwtx.ui.internal.forms.widgets.ObjectSegment; import dwtx.ui.internal.forms.widgets.ParagraphSegment; import dwtx.ui.internal.forms.widgets.Locator; import dwtx.ui.internal.forms.widgets.SelectionData; import dwt.DWT; import dwt.graphics.GC; import dwt.graphics.Point; import dwt.graphics.Rectangle; import dwt.dwthelper.utils; import dwtx.dwtxhelper.Collection; public abstract class ObjectSegment : ParagraphSegment { public static const int TOP = 1; public static const int MIDDLE = 2; public static const int BOTTOM = 3; private int alignment = BOTTOM; private bool nowrap=false; private Rectangle bounds; private String objectId; public int getVerticalAlignment() { return alignment; } void setVerticalAlignment(int alignment) { this.alignment = alignment; } public String getObjectId() { return objectId; } void setObjectId(String objectId) { this.objectId = objectId; } protected abstract Point getObjectSize(Hashtable resourceTable, int wHint); public bool advanceLocator(GC gc, int wHint, Locator loc, Hashtable objectTable, bool computeHeightOnly) { Point objectSize = getObjectSize(objectTable, wHint); int iwidth = 0; int iheight = 0; bool newLine = false; if (objectSize !is null) { iwidth = objectSize.x + (isSelectable()?2:0); iheight = objectSize.y + (isSelectable()?2:0); } if (wHint !is DWT.DEFAULT && !nowrap && loc.x + iwidth > wHint) { // new line if (computeHeightOnly) loc.collectHeights(); loc.x = loc.indent; loc.x += iwidth; loc.y += loc.rowHeight; loc.width = loc.indent + iwidth; loc.rowHeight = iheight; loc.leading = 0; newLine = true; } else { loc.x += iwidth; loc.width += iwidth; loc.rowHeight = Math.max(loc.rowHeight, iheight); } return newLine; } public bool contains(int x, int y) { if (bounds is null) return false; return bounds.contains(x, y); } public bool intersects(Rectangle rect) { if (bounds is null) return false; return bounds.intersects(rect); } public Rectangle getBounds() { return bounds; } public bool isSelectable() { return false; } /** * @return Returns the nowrap. */ public bool isNowrap() { return nowrap; } /** * @param nowrap The nowrap to set. */ public void setNowrap(bool nowrap) { this.nowrap = nowrap; } public void paint(GC gc, bool hover, Hashtable resourceTable, bool selected, SelectionData selData, Rectangle repaintRegion) { } /* (non-Javadoc) * @see dwtx.ui.internal.forms.widgets.ParagraphSegment#layout(dwt.graphics.GC, int, dwtx.ui.internal.forms.widgets.Locator, java.util.Hashtable, bool, dwtx.ui.internal.forms.widgets.SelectionData) */ public void layout(GC gc, int width, Locator loc, Hashtable resourceTable, bool selected) { Point size = getObjectSize(resourceTable, width); int objWidth = 0; int objHeight = 0; if (size !is null) { objWidth = size.x + (isSelectable()?2:0); objHeight = size.y + (isSelectable()?2:0); } else return; loc.width = objWidth; if (!nowrap && loc.x + objWidth > width) { // new row loc.newLine(); loc.rowCounter++; } int ix = loc.x; int iy = loc.y; if (alignment is MIDDLE) iy = loc.getMiddle(objHeight, false); else if (alignment is BOTTOM) iy = loc.getBaseline(objHeight, false); loc.x += objWidth; loc.rowHeight = Math.max(loc.rowHeight, objHeight); bounds = new Rectangle(ix, iy, objWidth, objHeight); } /* (non-Javadoc) * @see dwtx.ui.internal.forms.widgets.ParagraphSegment#computeSelection(dwt.graphics.GC, java.util.Hashtable, bool, dwtx.ui.internal.forms.widgets.SelectionData) */ public void computeSelection(GC gc, Hashtable resourceTable, SelectionData selData) { // TODO we should add this to the selection // if we want to support rich text } }