Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 60014 Details for
Bug 138579
StyledText: Support for custom double-click (+drag) behavior
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
patch for wordboundary listener
patch.txt (text/plain), 13.01 KB, created by
Felipe Heidrich
on 2007-02-28 15:06:10 EST
(
hide
)
Description:
patch for wordboundary listener
Filename:
MIME Type:
Creator:
Felipe Heidrich
Created:
2007-02-28 15:06:10 EST
Size:
13.01 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.swt >Index: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java,v >retrieving revision 1.17 >diff -u -r1.17 StyledTextListener.java >--- Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java 9 May 2006 19:47:06 -0000 1.17 >+++ Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java 28 Feb 2007 19:59:48 -0000 >@@ -24,7 +24,6 @@ > * Process StyledText events by invoking the event's handler. > */ > public void handleEvent(Event e) { >- TextChangedEvent textChangedEvent; > > switch (e.type) { > case StyledText.ExtendedModify: >@@ -61,18 +60,38 @@ > ((VerifyKeyListener) eventListener).verifyKey(verifyEvent); > e.doit = verifyEvent.doit; > break; >- case StyledText.TextChanged: >- textChangedEvent = new TextChangedEvent((StyledTextContent) e.data); >+ case StyledText.TextChanged: { >+ TextChangedEvent textChangedEvent = new TextChangedEvent((StyledTextContent) e.data); > ((TextChangeListener) eventListener).textChanged(textChangedEvent); > break; >+ } > case StyledText.TextChanging: > TextChangingEvent textChangingEvent = new TextChangingEvent((StyledTextContent) e.data, (StyledTextEvent) e); > ((TextChangeListener) eventListener).textChanging(textChangingEvent); > break; >- case StyledText.TextSet: >- textChangedEvent = new TextChangedEvent((StyledTextContent) e.data); >+ case StyledText.TextSet: { >+ TextChangedEvent textChangedEvent = new TextChangedEvent((StyledTextContent) e.data); > ((TextChangeListener) eventListener).textSet(textChangedEvent); > break; >+ } >+ case StyledText.WordNext: { >+ WordBoundaryEvent wordBoundaryEvent = new WordBoundaryEvent((StyledTextEvent) e); >+ ((WordBoundaryListener) eventListener).getWordNext(wordBoundaryEvent); >+ ((StyledTextEvent) e).count = wordBoundaryEvent.caretOffset; >+ break; >+ } >+ case StyledText.WordPrevious: { >+ WordBoundaryEvent wordBoundaryEvent = new WordBoundaryEvent((StyledTextEvent) e); >+ ((WordBoundaryListener) eventListener).getWordPrevious(wordBoundaryEvent); >+ ((StyledTextEvent) e).count = wordBoundaryEvent.caretOffset; >+ break; >+ } >+ case StyledText.WordNextNoSpaces: { >+ WordBoundaryEvent wordBoundaryEvent = new WordBoundaryEvent((StyledTextEvent) e); >+ ((WordBoundaryListener) eventListener).getWordNextNoSpaces(wordBoundaryEvent); >+ ((StyledTextEvent) e).count = wordBoundaryEvent.caretOffset; >+ break; >+ } > } > } > } >Index: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java,v >retrieving revision 1.350 >diff -u -r1.350 StyledText.java >--- Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java 14 Feb 2007 00:14:43 -0000 1.350 >+++ Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java 28 Feb 2007 19:59:48 -0000 >@@ -92,6 +92,9 @@ > static final int TextChanged = 3006; > static final int LineGetSegments = 3007; > static final int PaintObject = 3008; >+ static final int WordNext = 3009; >+ static final int WordPrevious = 3010; >+ static final int WordNextNoSpaces = 3011; > > static final int PREVIOUS_OFFSET_TRAILING = 0; > static final int OFFSET_LEADING = 1; >@@ -445,11 +448,24 @@ > printLayout.setFont(printerFont); > } > if (printOptions.printLineNumbers) { >+ int numberingWidth = 0; > int count = endLine - startLine + 1; >- StringBuffer buffer = new StringBuffer("0"); >- while ((count /= 10) > 0) buffer.append("0"); >- printLayout.setText(buffer.toString()); >- int numberingWidth = printLayout.getBounds().width + printMargin; >+ String[] lineLabels = printOptions.lineLabels; >+ if (lineLabels != null) { >+ for (int i = startLine; i < Math.min(count, lineLabels.length); i++) { >+ if (lineLabels[i] != null) { >+ printLayout.setText(lineLabels[i]); >+ int lineWidth = printLayout.getBounds().width; >+ numberingWidth = Math.max(numberingWidth, lineWidth); >+ } >+ } >+ } else { >+ StringBuffer buffer = new StringBuffer("0"); >+ while ((count /= 10) > 0) buffer.append("0"); >+ printLayout.setText(buffer.toString()); >+ numberingWidth = printLayout.getBounds().width; >+ } >+ numberingWidth += printMargin; > if (numberingWidth > width) numberingWidth = width; > paintX += numberingWidth; > width -= numberingWidth; >@@ -595,7 +611,16 @@ > FontMetrics metrics = layout.getLineMetrics(0); > printLayout.setAscent(metrics.getAscent() + metrics.getDescent()); > printLayout.setDescent(metrics.getDescent()); >- printLayout.setText(String.valueOf(index)); >+ String[] lineLabels = printOptions.lineLabels; >+ if (lineLabels != null) { >+ if (0 <= index && index < lineLabels.length && lineLabels[index] != null) { >+ printLayout.setText(lineLabels[index]); >+ } else { >+ printLayout.setText(""); >+ } >+ } else { >+ printLayout.setText(String.valueOf(index)); >+ } > int paintX = x - printMargin - printLayout.getBounds().width; > printLayout.draw(gc, paintX, y); > printLayout.setAscent(-1); >@@ -1426,6 +1451,13 @@ > if (verifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); > addListener(SWT.Verify, new TypedListener(verifyListener)); > } >+public void addWordBoundaryListener(WordBoundaryListener listener) { >+ checkWidget(); >+ if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); >+ addListener(WordNext, new StyledTextListener(listener)); >+ addListener(WordPrevious, new StyledTextListener(listener)); >+ addListener(WordNextNoSpaces, new StyledTextListener(listener)); >+} > /** > * Appends a string to the text at the end of the widget. > * >@@ -4615,6 +4647,9 @@ > * </p> > */ > int getWordEnd(int offset) { >+ int eventOffset = sendWordBoundaryEvent(WordNext, offset); >+ if (eventOffset != SWT.DEFAULT) return eventOffset; >+ > if (offset >= getCharCount()) { > return offset; > } >@@ -4647,6 +4682,9 @@ > * </p> > */ > int getWordEndNoSpaces(int offset) { >+ int eventOffset = sendWordBoundaryEvent(WordNextNoSpaces, offset); >+ if (eventOffset != SWT.DEFAULT) return eventOffset; >+ > if (offset >= getCharCount()) { > return offset; > } >@@ -4687,6 +4725,9 @@ > * </p> > */ > int getWordStart(int offset) { >+ int eventOffset = sendWordBoundaryEvent(WordPrevious, offset); >+ if (eventOffset != SWT.DEFAULT) return eventOffset; >+ > if (offset <= 0) { > return offset; > } >@@ -6196,6 +6237,13 @@ > if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); > removeListener(VerifyKey, listener); > } >+public void removeWordBoundaryListener(WordBoundaryListener listener) { >+ checkWidget(); >+ if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); >+ removeListener(WordNext, listener); >+ removeListener(WordPrevious, listener); >+ removeListener(WordNextNoSpaces, listener); >+} > /** > * Replaces the styles in the given range with new styles. This method > * effectively deletes the styles in the given range and then adds the >@@ -6545,6 +6593,32 @@ > event.y = selection.y; > notifyListeners(SWT.Selection, event); > } >+int sendWordBoundaryEvent(int eventType, int offset) { >+ if (isListening(eventType)) { >+ StyledTextEvent event = new StyledTextEvent(content); >+ int lineIndex = content.getLineAtOffset(offset); >+ int lineOffset = content.getOffsetAtLine(lineIndex); >+ String lineText = content.getLine(lineIndex); >+ event.detail = lineOffset; >+ event.text = lineText; >+ event.count = offset; >+ notifyListeners(eventType, event); >+ offset = event.count; >+ if (offset == SWT.DEFAULT) return SWT.DEFAULT; >+ int length = getCharCount(); >+ if (offset < 0) { >+ offset = 0; >+ } else if (offset > length) { >+ offset = length; >+ } else { >+ if (isLineDelimiter(offset)) { >+ SWT.error(SWT.ERROR_INVALID_ARGUMENT); >+ } >+ } >+ return offset; >+ } >+ return SWT.DEFAULT; >+} > /** > * Sets the alignment of the widget. The argument should be one of <code>SWT.LEFT</code>, > * <code>SWT.CENTER</code> or <code>SWT.RIGHT</code>. The alignment applies for all lines. >Index: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java,v >retrieving revision 1.14 >diff -u -r1.14 StyledTextEvent.java >--- Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java 9 May 2006 19:47:06 -0000 1.14 >+++ Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java 28 Feb 2007 19:59:48 -0000 >@@ -39,7 +39,6 @@ > int y; > int ascent; > int descent; >- GC gc; > StyleRange style; > > StyledTextEvent (StyledTextContent content) { >Index: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java,v >retrieving revision 1.9 >diff -u -r1.9 StyledTextPrintOptions.java >--- Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java 20 Jul 2006 19:43:40 -0000 1.9 >+++ Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java 28 Feb 2007 19:59:48 -0000 >@@ -91,5 +91,11 @@ > */ > public boolean printLineNumbers = false; > >+ /** >+ * Line labels. >+ * >+ * @since 3.3 >+ */ >+ public String[] lineLabels = null; > > } >Index: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/WordBoundaryEvent.java >=================================================================== >RCS file: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/WordBoundaryEvent.java >diff -N Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/WordBoundaryEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/WordBoundaryEvent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,45 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.swt.custom; >+ >+import org.eclipse.swt.events.*; >+ >+/** >+ * This event is sent when a line is about to be drawn. >+ */ >+public class WordBoundaryEvent extends TypedEvent { >+ >+ /** >+ * line start offset >+ */ >+ public int lineOffset; >+ >+ /** >+ * line text >+ */ >+ public String lineText; >+ >+ /** >+ * caret offset, input/ouput parameter >+ */ >+ public int caretOffset; >+ >+ static final long serialVersionUID = 3978765487853324342L; >+ >+public WordBoundaryEvent(StyledTextEvent e) { >+ super(e); >+ lineOffset = e.detail; >+ lineText = e.text; >+ caretOffset = e.count; >+} >+} >+ >+ >Index: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/WordBoundaryListener.java >=================================================================== >RCS file: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/WordBoundaryListener.java >diff -N Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/WordBoundaryListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/WordBoundaryListener.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.swt.custom; >+ >+import org.eclipse.swt.internal.SWTEventListener; >+ >+public interface WordBoundaryListener extends SWTEventListener { >+/** >+ * The following event fields are used:<ul> >+ * <li>event.lineText is the ?????? (input)</li> >+ * <li>event.doit is processed or not (output)</li> >+ * </ul> >+ * @param event the verify event???? >+ */ >+public void getWordNext (WordBoundaryEvent event); >+ >+public void getWordPrevious (WordBoundaryEvent event); >+ >+public void getWordNextNoSpaces (WordBoundaryEvent event); >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 138579
:
46449
| 60014