Mercurial > projects > dwt-addons
annotate 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 |
rev | line source |
---|---|
75 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.ui.internal.forms.widgets.SelectionData; | |
14 | |
15 import dwtx.ui.internal.forms.widgets.Locator; | |
16 | |
17 import dwt.DWT; | |
18 import dwt.events.MouseEvent; | |
19 import dwt.graphics.Color; | |
20 import dwt.graphics.Point; | |
21 import dwt.widgets.Display; | |
22 | |
23 import dwt.dwthelper.utils; | |
24 import tango.util.collection.ArraySeq; | |
25 static import tango.text.Text; | |
26 | |
27 public class SelectionData { | |
28 public Display display; | |
29 public Color bg; | |
30 public Color fg; | |
31 private Point start; | |
32 private Point stop; | |
33 private ArraySeq!(String) segments; | |
34 private bool newLineNeeded; | |
35 | |
36 public this(MouseEvent e) { | |
37 display = e.display; | |
38 segments = new ArraySeq!(String); | |
39 start = new Point(e.x, e.y); | |
40 stop = new Point(e.x, e.y); | |
41 bg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION); | |
42 fg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION_TEXT); | |
43 } | |
44 | |
45 public void markNewLine() { | |
46 newLineNeeded=true; | |
47 } | |
48 public void addSegment(String text) { | |
49 if (newLineNeeded) { | |
50 segments.append(System.getProperty("line.separator")); //$NON-NLS-1$ | |
51 newLineNeeded=false; | |
52 } | |
53 segments.append(text); | |
54 } | |
55 | |
56 public void update(MouseEvent e) { | |
57 //Control c = (Control)e.widget; | |
58 stop.x = e.x; | |
59 stop.y = e.y; | |
60 } | |
61 public void reset() { | |
62 segments.clear(); | |
63 } | |
64 public String getSelectionText() { | |
65 auto buf = new tango.text.Text.Text!(char); | |
66 for (int i=0; i<segments.size(); i++) { | |
67 buf.append(segments.get(i)); | |
68 } | |
69 return buf.toString(); | |
70 } | |
71 public bool canCopy() { | |
72 return segments.size()>0; | |
73 } | |
74 | |
75 private int getTopOffset() { | |
76 return start.y<stop.y?start.y:stop.y; | |
77 } | |
78 private int getBottomOffset() { | |
79 return start.y>stop.y?start.y:stop.y; | |
80 } | |
81 public int getLeftOffset(Locator locator) { | |
82 return isInverted(locator)? stop.x:start.x; | |
83 } | |
84 public int getLeftOffset(int rowHeight) { | |
85 return isInverted(rowHeight) ? stop.x:start.x; | |
86 } | |
87 public int getRightOffset(Locator locator) { | |
88 return isInverted(locator)? start.x: stop.x; | |
89 } | |
90 public int getRightOffset(int rowHeight) { | |
91 return isInverted(rowHeight) ? start.x:stop.x; | |
92 } | |
93 private bool isInverted(Locator locator) { | |
94 int rowHeight = locator.heights.get(locator.rowCounter).array[0]; | |
95 return isInverted(rowHeight); | |
96 } | |
97 private bool isInverted(int rowHeight) { | |
98 int deltaY = start.y - stop.y; | |
99 if (Math.abs(deltaY) > rowHeight) { | |
100 // inter-row selection | |
101 return deltaY>0; | |
102 } | |
103 // intra-row selection | |
104 return start.x > stop.x; | |
105 } | |
106 public bool isEnclosed() { | |
77
26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
107 return !start.opEquals(stop); |
75 | 108 } |
109 | |
110 public bool isSelectedRow(Locator locator) { | |
111 if (!isEnclosed()) | |
112 return false; | |
113 int rowHeight = locator.heights.get(locator.rowCounter).array[0]; | |
114 return isSelectedRow(locator.y, rowHeight); | |
115 } | |
116 public bool isSelectedRow(int y, int rowHeight) { | |
117 if (!isEnclosed()) | |
118 return false; | |
119 return (y + rowHeight >= getTopOffset() && | |
120 y <= getBottomOffset()); | |
121 } | |
122 public bool isFirstSelectionRow(Locator locator) { | |
123 if (!isEnclosed()) | |
124 return false; | |
125 int rowHeight = locator.heights.get(locator.rowCounter).array[0]; | |
126 return (locator.y + rowHeight >= getTopOffset() && | |
127 locator.y <= getTopOffset()); | |
128 } | |
129 public bool isFirstSelectionRow(int y, int rowHeight) { | |
130 if (!isEnclosed()) | |
131 return false; | |
132 return (y + rowHeight >= getTopOffset() && | |
133 y <= getTopOffset()); | |
134 } | |
135 public bool isLastSelectionRow(Locator locator) { | |
136 if (!isEnclosed()) | |
137 return false; | |
138 int rowHeight = locator.heights.get(locator.rowCounter).array[0]; | |
139 return (locator.y + rowHeight >=getBottomOffset() && | |
140 locator.y <= getBottomOffset()); | |
141 } | |
142 public bool isLastSelectionRow(int y, int rowHeight) { | |
143 if (!isEnclosed()) | |
144 return false; | |
145 return (y + rowHeight >=getBottomOffset() && | |
146 y <= getBottomOffset()); | |
147 } | |
148 } |