| 1 |
/******************************************************************************* |
|---|
| 2 |
* Copyright (c) 2000, 2008 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 dwt.custom.BidiSegmentEvent; |
|---|
| 14 |
|
|---|
| 15 |
import dwt.dwthelper.utils; |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
import dwt.events.TypedEvent; |
|---|
| 19 |
import dwt.custom.StyledTextEvent; |
|---|
| 20 |
|
|---|
| 21 |
/** |
|---|
| 22 |
* This event is sent to BidiSegmentListeners when a line is to |
|---|
| 23 |
* be measured or rendered in a bidi locale. The segments field is |
|---|
| 24 |
* used to specify text ranges in the line that should be treated as |
|---|
| 25 |
* separate segments for bidi reordering. Each segment will be reordered |
|---|
| 26 |
* and rendered separately. |
|---|
| 27 |
* <p> |
|---|
| 28 |
* The elements in the segments field specify the start offset of |
|---|
| 29 |
* a segment relative to the start of the line. They must follow |
|---|
| 30 |
* the following rules: |
|---|
| 31 |
* <ul> |
|---|
| 32 |
* <li>first element must be 0 |
|---|
| 33 |
* <li>elements must be in ascending order and must not have duplicates |
|---|
| 34 |
* <li>elements must not exceed the line length |
|---|
| 35 |
* </ul> |
|---|
| 36 |
* In addition, the last element may be set to the end of the line |
|---|
| 37 |
* but this is not required. |
|---|
| 38 |
* |
|---|
| 39 |
* The segments field may be left null if the entire line should |
|---|
| 40 |
* be reordered as is. |
|---|
| 41 |
* </p> |
|---|
| 42 |
* A BidiSegmentListener may be used when adjacent segments of |
|---|
| 43 |
* right-to-left text should not be reordered relative to each other. |
|---|
| 44 |
* For example, within a Java editor, you may wish multiple |
|---|
| 45 |
* right-to-left string literals to be reordered differently than the |
|---|
| 46 |
* bidi algorithm specifies. |
|---|
| 47 |
* |
|---|
| 48 |
* Example: |
|---|
| 49 |
* <pre> |
|---|
| 50 |
* stored line = "R1R2R3" + "R4R5R6" |
|---|
| 51 |
* R1 to R6 are right-to-left characters. The quotation marks |
|---|
| 52 |
* are part of the line text. The line is 13 characters long. |
|---|
| 53 |
* |
|---|
| 54 |
* segments = null: |
|---|
| 55 |
* entire line will be reordered and thus the two R2L segments |
|---|
| 56 |
* swapped (as per the bidi algorithm). |
|---|
| 57 |
* visual line (rendered on screen) = "R6R5R4" + "R3R2R1" |
|---|
| 58 |
* |
|---|
| 59 |
* segments = [0, 5, 8] |
|---|
| 60 |
* "R1R2R3" will be reordered, followed by [blank]+[blank] and |
|---|
| 61 |
* "R4R5R6". |
|---|
| 62 |
* visual line = "R3R2R1" + "R6R5R4" |
|---|
| 63 |
* </pre> |
|---|
| 64 |
* |
|---|
| 65 |
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
|---|
| 66 |
*/ |
|---|
| 67 |
public class BidiSegmentEvent : TypedEvent { |
|---|
| 68 |
|
|---|
| 69 |
/** |
|---|
| 70 |
* line start offset |
|---|
| 71 |
*/ |
|---|
| 72 |
public int lineOffset; |
|---|
| 73 |
|
|---|
| 74 |
/** |
|---|
| 75 |
* line text |
|---|
| 76 |
*/ |
|---|
| 77 |
public String lineText; |
|---|
| 78 |
|
|---|
| 79 |
/** |
|---|
| 80 |
* bidi segments, see above |
|---|
| 81 |
*/ |
|---|
| 82 |
public int[] segments; |
|---|
| 83 |
|
|---|
| 84 |
this(StyledTextEvent e) { |
|---|
| 85 |
super(cast(Object)e); |
|---|
| 86 |
lineOffset = e.detail; |
|---|
| 87 |
lineText = e.text; |
|---|
| 88 |
} |
|---|
| 89 |
} |
|---|