Mercurial > projects > dwt-addons
annotate dwtx/ui/internal/forms/widgets/SelectionData.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 |
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; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
24 import dwtx.dwtxhelper.Collection; |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
25 |
75 | 26 static import tango.text.Text; |
27 | |
28 public class SelectionData { | |
29 public Display display; | |
30 public Color bg; | |
31 public Color fg; | |
32 private Point start; | |
33 private Point stop; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
34 private ArrayList segments; |
75 | 35 private bool newLineNeeded; |
36 | |
37 public this(MouseEvent e) { | |
38 display = e.display; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
39 segments = new ArrayList(); |
75 | 40 start = new Point(e.x, e.y); |
41 stop = new Point(e.x, e.y); | |
42 bg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION); | |
43 fg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION_TEXT); | |
44 } | |
45 | |
46 public void markNewLine() { | |
47 newLineNeeded=true; | |
48 } | |
49 public void addSegment(String text) { | |
50 if (newLineNeeded) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
51 segments.add(System.getProperty("line.separator")); //$NON-NLS-1$ |
75 | 52 newLineNeeded=false; |
53 } | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
54 segments.add(text); |
75 | 55 } |
56 | |
57 public void update(MouseEvent e) { | |
58 //Control c = (Control)e.widget; | |
59 stop.x = e.x; | |
60 stop.y = e.y; | |
61 } | |
62 public void reset() { | |
63 segments.clear(); | |
64 } | |
65 public String getSelectionText() { | |
66 auto buf = new tango.text.Text.Text!(char); | |
67 for (int i=0; i<segments.size(); i++) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
68 buf.append(stringcast(segments.get(i))); |
75 | 69 } |
70 return buf.toString(); | |
71 } | |
72 public bool canCopy() { | |
73 return segments.size()>0; | |
74 } | |
75 | |
76 private int getTopOffset() { | |
77 return start.y<stop.y?start.y:stop.y; | |
78 } | |
79 private int getBottomOffset() { | |
80 return start.y>stop.y?start.y:stop.y; | |
81 } | |
82 public int getLeftOffset(Locator locator) { | |
83 return isInverted(locator)? stop.x:start.x; | |
84 } | |
85 public int getLeftOffset(int rowHeight) { | |
86 return isInverted(rowHeight) ? stop.x:start.x; | |
87 } | |
88 public int getRightOffset(Locator locator) { | |
89 return isInverted(locator)? start.x: stop.x; | |
90 } | |
91 public int getRightOffset(int rowHeight) { | |
92 return isInverted(rowHeight) ? start.x:stop.x; | |
93 } | |
94 private bool isInverted(Locator locator) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
95 int rowHeight = arrayFromObject!(Integer)(locator.heights.get(locator.rowCounter))[0].value; |
75 | 96 return isInverted(rowHeight); |
97 } | |
98 private bool isInverted(int rowHeight) { | |
99 int deltaY = start.y - stop.y; | |
100 if (Math.abs(deltaY) > rowHeight) { | |
101 // inter-row selection | |
102 return deltaY>0; | |
103 } | |
104 // intra-row selection | |
105 return start.x > stop.x; | |
106 } | |
107 public bool isEnclosed() { | |
77
26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
108 return !start.opEquals(stop); |
75 | 109 } |
110 | |
111 public bool isSelectedRow(Locator locator) { | |
112 if (!isEnclosed()) | |
113 return false; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
114 int rowHeight = arrayFromObject!(Integer)(locator.heights.get(locator.rowCounter))[0].value; |
75 | 115 return isSelectedRow(locator.y, rowHeight); |
116 } | |
117 public bool isSelectedRow(int y, int rowHeight) { | |
118 if (!isEnclosed()) | |
119 return false; | |
120 return (y + rowHeight >= getTopOffset() && | |
121 y <= getBottomOffset()); | |
122 } | |
123 public bool isFirstSelectionRow(Locator locator) { | |
124 if (!isEnclosed()) | |
125 return false; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
126 int rowHeight = arrayFromObject!(Integer)(locator.heights.get(locator.rowCounter))[0].value; |
75 | 127 return (locator.y + rowHeight >= getTopOffset() && |
128 locator.y <= getTopOffset()); | |
129 } | |
130 public bool isFirstSelectionRow(int y, int rowHeight) { | |
131 if (!isEnclosed()) | |
132 return false; | |
133 return (y + rowHeight >= getTopOffset() && | |
134 y <= getTopOffset()); | |
135 } | |
136 public bool isLastSelectionRow(Locator locator) { | |
137 if (!isEnclosed()) | |
138 return false; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
139 int rowHeight = arrayFromObject!(Integer)(locator.heights.get(locator.rowCounter))[0].value; |
75 | 140 return (locator.y + rowHeight >=getBottomOffset() && |
141 locator.y <= getBottomOffset()); | |
142 } | |
143 public bool isLastSelectionRow(int y, int rowHeight) { | |
144 if (!isEnclosed()) | |
145 return false; | |
146 return (y + rowHeight >=getBottomOffset() && | |
147 y <= getBottomOffset()); | |
148 } | |
149 } |