1 /*******************************************************************************
2  * Copyright (c) 2009, 2017 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  *     alice <stigma@disroot.org>
12  *******************************************************************************/
13 module org.eclipse.swt.accessibility.AccessibleTextAttributeEvent;
14 
15 import java.lang.all;
16 import java.util.EventObject;
17 
18 
19 import org.eclipse.swt.graphics.all;
20 
21 import std.conv : to;
22 
23 /**
24  * Instances of this class are sent as a result of accessibility clients
25  * sending AccessibleAttribute or AccessibleEditableText messages to an
26  * accessible object.
27  *
28  * @see AccessibleAttributeListener
29  * @see AccessibleAttributeAdapter
30  * @see AccessibleEditableTextListener
31  * @see AccessibleEditableTextAdapter
32  *
33  * @since 3.6
34  */
35 public class AccessibleTextAttributeEvent : EventObject {
36 
37     /**
38      * [in] the 0-based text offset for which to return attribute information
39      *
40      * @see AccessibleAttributeListener#getTextAttributes
41      */
42     public int offset;
43 
44     /**
45      * [in/out] the starting and ending offsets of the character range
46      *
47      * @see AccessibleAttributeListener#getTextAttributes
48      * @see AccessibleEditableTextListener#setTextAttributes
49      */
50     public int start, end;
51 
52     /**
53      * [in/out] the TextStyle of the character range
54      *
55      * @see AccessibleAttributeListener#getTextAttributes
56      * @see AccessibleEditableTextListener#setTextAttributes
57      */
58     public TextStyle textStyle;
59 
60     /**
61      * [in/out] an array of alternating key and value Strings
62      * that represent attributes that do not correspond to TextStyle fields
63      *
64      * @see AccessibleAttributeListener#getTextAttributes
65      * @see AccessibleEditableTextListener#setTextAttributes
66      */
67     public String [] attributes;
68 
69     /**
70      * [out] Set this field to {@link ACC#OK} if the operation
71      * was completed successfully, and null otherwise.
72      *
73      * @see AccessibleEditableTextListener#setTextAttributes
74      *
75      * @since 3.7
76      */
77     public String result;
78 
79     // static const long serialVersionUID = 7131825608864332802L;
80 
81 /**
82  * Constructs a new instance of this class.
83  *
84  * @param source the object that fired the event
85  */
86 public this(Object source) {
87     super(source);
88 }
89 
90 /**
91  * Returns a string containing a concise, human-readable
92  * description of the receiver.
93  *
94  * @return a string representation of the event
95  */
96 override
97 public String toString () const {
98     return Format("AccessibleAttributeEvent {{ offset={} start={} end={} textStyle={} attributes={} result={}}",
99         offset,
100         start,
101         end,
102         textStyle.toString(),
103         attributes,
104         result);
105 }
106 
107 package String toAttributeString(String [] attributes) {
108     if (attributes == null || attributes.length == 0) return to!String(attributes);   //$NON-NLS-1$
109     StringBuffer attributeString = new StringBuffer();
110     for (int i = 0; i < attributes.length; i++) {
111         attributeString.append(attributes[i]);
112         attributeString.append((i % 2 == 0) ? ":" : ";");   //$NON-NLS-1$   //$NON-NLS-2$
113     }
114     return attributeString.toString();
115 }
116 }