Mercurial > projects > dwt-addons
diff dwtx/ui/internal/forms/widgets/ObjectSegment.d @ 75:5d489b9f966c
Fix continue porting
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 24 May 2008 05:11:16 +0200 |
parents | |
children | 26c6c9dfd13c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/ui/internal/forms/widgets/ObjectSegment.d Sat May 24 05:11:16 2008 +0200 @@ -0,0 +1,158 @@ +/******************************************************************************* + * 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; + +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 (boundsisnull) + return false; + return bounds.contains(x, y); + } + public bool intersects(Rectangle rect) { + if (boundsisnull) + 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 (alignmentisMIDDLE) + iy = loc.getMiddle(objHeight, false); + else if (alignmentisBOTTOM) + 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 + } +}