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 org.eclipse.swt.custom.StyledTextListener;
14 
15 
16 import org.eclipse.swt.events.VerifyEvent;
17 import org.eclipse.swt.internal.SWTEventListener;
18 import org.eclipse.swt.widgets.Event;
19 import org.eclipse.swt.widgets.TypedListener;
20 import org.eclipse.swt.custom.StyledText;
21 import org.eclipse.swt.custom.ExtendedModifyEvent;
22 import org.eclipse.swt.custom.ExtendedModifyListener;
23 import org.eclipse.swt.custom.StyledTextEvent;
24 import org.eclipse.swt.custom.LineBackgroundEvent;
25 import org.eclipse.swt.custom.BidiSegmentEvent;
26 import org.eclipse.swt.custom.LineStyleEvent;
27 import org.eclipse.swt.custom.PaintObjectEvent;
28 import org.eclipse.swt.custom.MovementEvent;
29 import org.eclipse.swt.custom.TextChangedEvent;
30 import org.eclipse.swt.custom.TextChangingEvent;
31 import org.eclipse.swt.custom.LineBackgroundListener;
32 import org.eclipse.swt.custom.BidiSegmentListener;
33 import org.eclipse.swt.custom.LineStyleListener;
34 import org.eclipse.swt.custom.PaintObjectListener;
35 import org.eclipse.swt.custom.VerifyKeyListener;
36 import org.eclipse.swt.custom.StyledTextContent;
37 import org.eclipse.swt.custom.TextChangeListener;
38 import org.eclipse.swt.custom.MovementListener;
39 
40 
41 class StyledTextListener : TypedListener {
42 /**
43  */
44 this(SWTEventListener listener) {
45     super(listener);
46 }
47 /**
48  * Process StyledText events by invoking the event's handler.
49  *
50  * @param e the event to handle
51  */
52 public override void handleEvent(Event e) {
53 
54     switch (e.type) {
55         case StyledText.ExtendedModify:
56             ExtendedModifyEvent extendedModifyEvent = new ExtendedModifyEvent(cast(StyledTextEvent) e);
57             (cast(ExtendedModifyListener) eventListener).modifyText(extendedModifyEvent);
58             break;
59         case StyledText.LineGetBackground:
60             LineBackgroundEvent lineBgEvent = new LineBackgroundEvent(cast(StyledTextEvent) e);
61             (cast(LineBackgroundListener) eventListener).lineGetBackground(lineBgEvent);
62             (cast(StyledTextEvent) e).lineBackground = lineBgEvent.lineBackground;
63             break;
64         case StyledText.LineGetSegments:
65             BidiSegmentEvent segmentEvent = new BidiSegmentEvent(cast(StyledTextEvent) e);
66             (cast(BidiSegmentListener) eventListener).lineGetSegments(segmentEvent);
67             (cast(StyledTextEvent) e).segments = segmentEvent.segments;
68             break;
69         case StyledText.LineGetStyle:
70             LineStyleEvent lineStyleEvent = new LineStyleEvent(cast(StyledTextEvent) e);
71             (cast(LineStyleListener) eventListener).lineGetStyle(lineStyleEvent);
72             (cast(StyledTextEvent) e).ranges = lineStyleEvent.ranges;
73             (cast(StyledTextEvent) e).styles = lineStyleEvent.styles;
74             (cast(StyledTextEvent) e).alignment = lineStyleEvent.alignment;
75             (cast(StyledTextEvent) e).indent = lineStyleEvent.indent;
76             (cast(StyledTextEvent) e).justify = lineStyleEvent.justify;
77             (cast(StyledTextEvent) e).bullet = lineStyleEvent.bullet;
78             (cast(StyledTextEvent) e).bulletIndex = lineStyleEvent.bulletIndex;
79             break;
80         case StyledText.PaintObject:
81             PaintObjectEvent paintObjectEvent = new PaintObjectEvent(cast(StyledTextEvent) e);
82             (cast(PaintObjectListener) eventListener).paintObject(paintObjectEvent);
83             break;
84         case StyledText.VerifyKey:
85             VerifyEvent verifyEvent = new VerifyEvent(e);
86             (cast(VerifyKeyListener) eventListener).verifyKey(verifyEvent);
87             e.doit = verifyEvent.doit;
88             break;
89         case StyledText.TextChanged: {
90             TextChangedEvent textChangedEvent = new TextChangedEvent(cast(StyledTextContent) e.data);
91             (cast(TextChangeListener) eventListener).textChanged(textChangedEvent);
92             break;
93         }
94         case StyledText.TextChanging:
95             TextChangingEvent textChangingEvent = new TextChangingEvent(cast(StyledTextContent) e.data, cast(StyledTextEvent) e);
96             (cast(TextChangeListener) eventListener).textChanging(textChangingEvent);
97             break;
98         case StyledText.TextSet: {
99             TextChangedEvent textChangedEvent = new TextChangedEvent(cast(StyledTextContent) e.data);
100             (cast(TextChangeListener) eventListener).textSet(textChangedEvent);
101             break;
102         }
103         case StyledText.WordNext: {
104             MovementEvent wordBoundaryEvent = new MovementEvent(cast(StyledTextEvent) e);
105             (cast(MovementListener) eventListener).getNextOffset(wordBoundaryEvent);
106             (cast(StyledTextEvent) e).end = wordBoundaryEvent.newOffset;
107             break;
108         }
109         case StyledText.WordPrevious: {
110             MovementEvent wordBoundaryEvent = new MovementEvent(cast(StyledTextEvent) e);
111             (cast(MovementListener) eventListener).getPreviousOffset(wordBoundaryEvent);
112             (cast(StyledTextEvent) e).end = wordBoundaryEvent.newOffset;
113             break;
114         }
115         default:
116     }
117 }
118 }
119 
120