Mercurial > projects > dwt-addons
view dwtx/ui/internal/forms/widgets/SelectionData.d @ 77:26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 24 May 2008 06:59:31 +0200 |
parents | 5d489b9f966c |
children | 04b47443bb01 |
line wrap: on
line source
/******************************************************************************* * Copyright (c) 2000, 2005 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.SelectionData; import dwtx.ui.internal.forms.widgets.Locator; import dwt.DWT; import dwt.events.MouseEvent; import dwt.graphics.Color; import dwt.graphics.Point; import dwt.widgets.Display; import dwt.dwthelper.utils; import tango.util.collection.ArraySeq; static import tango.text.Text; public class SelectionData { public Display display; public Color bg; public Color fg; private Point start; private Point stop; private ArraySeq!(String) segments; private bool newLineNeeded; public this(MouseEvent e) { display = e.display; segments = new ArraySeq!(String); start = new Point(e.x, e.y); stop = new Point(e.x, e.y); bg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION); fg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION_TEXT); } public void markNewLine() { newLineNeeded=true; } public void addSegment(String text) { if (newLineNeeded) { segments.append(System.getProperty("line.separator")); //$NON-NLS-1$ newLineNeeded=false; } segments.append(text); } public void update(MouseEvent e) { //Control c = (Control)e.widget; stop.x = e.x; stop.y = e.y; } public void reset() { segments.clear(); } public String getSelectionText() { auto buf = new tango.text.Text.Text!(char); for (int i=0; i<segments.size(); i++) { buf.append(segments.get(i)); } return buf.toString(); } public bool canCopy() { return segments.size()>0; } private int getTopOffset() { return start.y<stop.y?start.y:stop.y; } private int getBottomOffset() { return start.y>stop.y?start.y:stop.y; } public int getLeftOffset(Locator locator) { return isInverted(locator)? stop.x:start.x; } public int getLeftOffset(int rowHeight) { return isInverted(rowHeight) ? stop.x:start.x; } public int getRightOffset(Locator locator) { return isInverted(locator)? start.x: stop.x; } public int getRightOffset(int rowHeight) { return isInverted(rowHeight) ? start.x:stop.x; } private bool isInverted(Locator locator) { int rowHeight = locator.heights.get(locator.rowCounter).array[0]; return isInverted(rowHeight); } private bool isInverted(int rowHeight) { int deltaY = start.y - stop.y; if (Math.abs(deltaY) > rowHeight) { // inter-row selection return deltaY>0; } // intra-row selection return start.x > stop.x; } public bool isEnclosed() { return !start.opEquals(stop); } public bool isSelectedRow(Locator locator) { if (!isEnclosed()) return false; int rowHeight = locator.heights.get(locator.rowCounter).array[0]; return isSelectedRow(locator.y, rowHeight); } public bool isSelectedRow(int y, int rowHeight) { if (!isEnclosed()) return false; return (y + rowHeight >= getTopOffset() && y <= getBottomOffset()); } public bool isFirstSelectionRow(Locator locator) { if (!isEnclosed()) return false; int rowHeight = locator.heights.get(locator.rowCounter).array[0]; return (locator.y + rowHeight >= getTopOffset() && locator.y <= getTopOffset()); } public bool isFirstSelectionRow(int y, int rowHeight) { if (!isEnclosed()) return false; return (y + rowHeight >= getTopOffset() && y <= getTopOffset()); } public bool isLastSelectionRow(Locator locator) { if (!isEnclosed()) return false; int rowHeight = locator.heights.get(locator.rowCounter).array[0]; return (locator.y + rowHeight >=getBottomOffset() && locator.y <= getBottomOffset()); } public bool isLastSelectionRow(int y, int rowHeight) { if (!isEnclosed()) return false; return (y + rowHeight >=getBottomOffset() && y <= getBottomOffset()); } }