View | Details | Raw Unified | Return to bug 298392 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/text/TextViewer.java (-157 / +178 lines)
Lines 22-27 Link Here
22
import java.util.regex.PatternSyntaxException;
22
import java.util.regex.PatternSyntaxException;
23
23
24
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.custom.Field3270;
25
import org.eclipse.swt.custom.LineBackgroundEvent;
26
import org.eclipse.swt.custom.LineBackgroundEvent;
26
import org.eclipse.swt.custom.LineBackgroundListener;
27
import org.eclipse.swt.custom.LineBackgroundListener;
27
import org.eclipse.swt.custom.MovementEvent;
28
import org.eclipse.swt.custom.MovementEvent;
Lines 135-140 Link Here
135
	 */
136
	 */
136
	private static final int TEXT_HOVER_HEIGHT_CHARS= 12; //used to be 10 (text font)
137
	private static final int TEXT_HOVER_HEIGHT_CHARS= 12; //used to be 10 (text font)
137
138
139
	private boolean is3270SupportRequired; //ira
140
	
138
	/**
141
	/**
139
	 * Represents a replace command that brings the text viewer's text widget
142
	 * Represents a replace command that brings the text viewer's text widget
140
	 * back in synchronization with text viewer's document after the document
143
	 * back in synchronization with text viewer's document after the document
Lines 309-316 Link Here
309
		 * @see MouseListener#mouseUp
312
		 * @see MouseListener#mouseUp
310
		 */
313
		 */
311
		public void mouseUp(MouseEvent e) {
314
		public void mouseUp(MouseEvent e) {
312
			if (fTextWidget != null)
315
			if (getTextWidget() != null)
313
				fTextWidget.removeSelectionListener(this);
316
				getTextWidget().removeSelectionListener(this);
314
			updateViewportListeners(MOUSE_END);
317
			updateViewportListeners(MOUSE_END);
315
		}
318
		}
316
319
Lines 318-325 Link Here
318
		 * @see MouseListener#mouseDown
321
		 * @see MouseListener#mouseDown
319
		 */
322
		 */
320
		public void mouseDown(MouseEvent e) {
323
		public void mouseDown(MouseEvent e) {
321
			if (fTextWidget != null)
324
			if (getTextWidget() != null)
322
				fTextWidget.addSelectionListener(this);
325
				getTextWidget().addSelectionListener(this);
323
		}
326
		}
324
327
325
		/*
328
		/*
Lines 672-678 Link Here
672
		public void lineGetBackground(LineBackgroundEvent event) {
675
		public void lineGetBackground(LineBackgroundEvent event) {
673
			/* Don't use cached line information because of patched redrawing events. */
676
			/* Don't use cached line information because of patched redrawing events. */
674
677
675
			if (fTextWidget != null) {
678
			if (getTextWidget() != null) {
676
				int offset= widgetOffset2ModelOffset(event.lineOffset);
679
				int offset= widgetOffset2ModelOffset(event.lineOffset);
677
				if (fPosition.includes(offset))
680
				if (fPosition.includes(offset))
678
					event.lineBackground= fHighlightColor;
681
					event.lineBackground= fHighlightColor;
Lines 686-692 Link Here
686
		 */
689
		 */
687
		public void install() {
690
		public void install() {
688
			TextViewer.this.addTextListener(this);
691
			TextViewer.this.addTextListener(this);
689
			fTextWidget.addLineBackgroundListener(this);
692
			getTextWidget().addLineBackgroundListener(this);
690
693
691
			IDocument document= TextViewer.this.getDocument();
694
			IDocument document= TextViewer.this.getDocument();
692
			try {
695
			try {
Lines 716-723 Link Here
716
				document.removePosition(fPosition);
719
				document.removePosition(fPosition);
717
			}
720
			}
718
721
719
			if (fTextWidget != null && !fTextWidget.isDisposed())
722
			if (getTextWidget() != null && !getTextWidget().isDisposed())
720
				fTextWidget.removeLineBackgroundListener(this);
723
				getTextWidget().removeLineBackgroundListener(this);
721
724
722
			TextViewer.this.removeTextListener(this);
725
			TextViewer.this.removeTextListener(this);
723
726
Lines 728-735 Link Here
728
		 * Clears the highlighting of this range.
731
		 * Clears the highlighting of this range.
729
		 */
732
		 */
730
		private void clear() {
733
		private void clear() {
731
			if (fTextWidget != null && !fTextWidget.isDisposed())
734
			if (getTextWidget() != null && !getTextWidget().isDisposed())
732
				fTextWidget.redraw();
735
				getTextWidget().redraw();
733
		}
736
		}
734
737
735
		/**
738
		/**
Lines 741-758 Link Here
741
			int offset= widgetRegion.getOffset();
744
			int offset= widgetRegion.getOffset();
742
			int length= widgetRegion.getLength();
745
			int length= widgetRegion.getLength();
743
746
744
			int count= fTextWidget.getCharCount();
747
			int count= getTextWidget().getCharCount();
745
			if (offset + length >= count) {
748
			if (offset + length >= count) {
746
				length= count - offset; // clip
749
				length= count - offset; // clip
747
750
748
				Point upperLeft= fTextWidget.getLocationAtOffset(offset);
751
				Point upperLeft= getTextWidget().getLocationAtOffset(offset);
749
				Point lowerRight= fTextWidget.getLocationAtOffset(offset + length);
752
				Point lowerRight= getTextWidget().getLocationAtOffset(offset + length);
750
				int width= fTextWidget.getClientArea().width;
753
				int width= getTextWidget().getClientArea().width;
751
				int height= fTextWidget.getLineHeight(offset + length) + lowerRight.y - upperLeft.y;
754
				int height= getTextWidget().getLineHeight(offset + length) + lowerRight.y - upperLeft.y;
752
				fTextWidget.redraw(upperLeft.x, upperLeft.y, width, height, false);
755
				getTextWidget().redraw(upperLeft.x, upperLeft.y, width, height, false);
753
			}
756
			}
754
757
755
			fTextWidget.redrawRange(offset, length, true);
758
			getTextWidget().redrawRange(offset, length, true);
756
		}
759
		}
757
760
758
		/*
761
		/*
Lines 1390-1398 Link Here
1390
		 * Installs this cursor listener.
1393
		 * Installs this cursor listener.
1391
		 */
1394
		 */
1392
		private void install() {
1395
		private void install() {
1393
			if (fTextWidget != null && !fTextWidget.isDisposed()) {
1396
			if (getTextWidget() != null && !getTextWidget().isDisposed()) {
1394
				fTextWidget.addKeyListener(this);
1397
				getTextWidget().addKeyListener(this);
1395
				fTextWidget.addMouseListener(this);
1398
				getTextWidget().addMouseListener(this);
1396
			}
1399
			}
1397
		}
1400
		}
1398
1401
Lines 1400-1408 Link Here
1400
		 * Uninstalls this cursor listener.
1403
		 * Uninstalls this cursor listener.
1401
		 */
1404
		 */
1402
		private void uninstall() {
1405
		private void uninstall() {
1403
			if (fTextWidget != null && !fTextWidget.isDisposed()) {
1406
			if (getTextWidget() != null && !getTextWidget().isDisposed()) {
1404
				fTextWidget.removeKeyListener(this);
1407
				getTextWidget().removeKeyListener(this);
1405
				fTextWidget.removeMouseListener(this);
1408
				getTextWidget().removeMouseListener(this);
1406
			}
1409
			}
1407
		}
1410
		}
1408
1411
Lines 1416-1422 Link Here
1416
		 * @see KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1419
		 * @see KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1417
		 */
1420
		 */
1418
		public void keyReleased(KeyEvent e) {
1421
		public void keyReleased(KeyEvent e) {
1419
			if (fTextWidget.getSelectionCount() == 0) {
1422
			if (getTextWidget().getSelectionCount() == 0) {
1420
				fLastSentSelectionChange= null;
1423
				fLastSentSelectionChange= null;
1421
				queuePostSelectionChanged(e.character == SWT.DEL);
1424
				queuePostSelectionChanged(e.character == SWT.DEL);
1422
			}
1425
			}
Lines 1438-1444 Link Here
1438
		 * @see MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1441
		 * @see MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1439
		 */
1442
		 */
1440
		public void mouseUp(MouseEvent event) {
1443
		public void mouseUp(MouseEvent event) {
1441
			if (fTextWidget.getSelectionCount() == 0)
1444
			if (getTextWidget().getSelectionCount() == 0)
1442
				queuePostSelectionChanged(false);
1445
				queuePostSelectionChanged(false);
1443
		}
1446
		}
1444
	}
1447
	}
Lines 1522-1527 Link Here
1522
1525
1523
	/** The viewer's text widget */
1526
	/** The viewer's text widget */
1524
	private StyledText fTextWidget;
1527
	private StyledText fTextWidget;
1528
	private Field3270 fField3270Widget; //ira
1525
	/** The viewer's input document */
1529
	/** The viewer's input document */
1526
	private IDocument fDocument;
1530
	private IDocument fDocument;
1527
	/** The viewer's visible document */
1531
	/** The viewer's visible document */
Lines 1752-1757 Link Here
1752
		styledText.setLeftMargin(Math.max(styledText.getLeftMargin(), 2));
1756
		styledText.setLeftMargin(Math.max(styledText.getLeftMargin(), 2));
1753
		return styledText;
1757
		return styledText;
1754
	}
1758
	}
1759
	protected Field3270 createField3270Widget(Composite parent, int styles) {
1760
		Field3270 field3270 = new Field3270(parent, styles);
1761
		field3270.getStyledText().setLeftMargin(Math.max(field3270.getStyledText().getLeftMargin(), 2));
1762
		return field3270;
1763
	}
1755
1764
1756
	/**
1765
	/**
1757
	 * Factory method to create the document adapter to be used by this viewer.
1766
	 * Factory method to create the document adapter to be used by this viewer.
Lines 1770-1798 Link Here
1770
	 * @param styles the SWT style bits for the viewer's control
1779
	 * @param styles the SWT style bits for the viewer's control
1771
	 */
1780
	 */
1772
	protected void createControl(Composite parent, int styles) {
1781
	protected void createControl(Composite parent, int styles) {
1773
1782
		if (!is3270SupportRequired)
1774
		fTextWidget= createTextWidget(parent, styles);
1783
			fTextWidget= createTextWidget(parent, styles);
1784
		else
1785
			fField3270Widget = createField3270Widget(parent, styles);
1775
1786
1776
		// Support scroll page upon MOD1+MouseWheel
1787
		// Support scroll page upon MOD1+MouseWheel
1777
		fTextWidget.addListener(SWT.MouseVerticalWheel, new Listener() {
1788
		getTextWidget().addListener(SWT.MouseWheel, new Listener() {
1778
1789
1779
			public void handleEvent(Event event) {
1790
			public void handleEvent(Event event) {
1780
				if (((event.stateMask & SWT.MOD1) == 0))
1791
				if (((event.stateMask & SWT.MOD1) == 0))
1781
					return;
1792
					return;
1782
1793
1783
				int topIndex= fTextWidget.getTopIndex();
1794
				int topIndex= getTextWidget().getTopIndex();
1784
				int bottomIndex= JFaceTextUtil.getBottomIndex(fTextWidget);
1795
				int bottomIndex = JFaceTextUtil.getBottomIndex(getTextWidget());
1785
1796
1786
				if (event.count > 0)
1797
				if (event.count > 0)
1787
					fTextWidget.setTopIndex(2 * topIndex - bottomIndex);
1798
					getTextWidget().setTopIndex(2 * topIndex - bottomIndex);
1788
				else
1799
				else
1789
					fTextWidget.setTopIndex(bottomIndex);
1800
					getTextWidget().setTopIndex(bottomIndex);
1790
1801
1791
				updateViewportListeners(INTERNAL);
1802
				updateViewportListeners(INTERNAL);
1792
			}
1803
			}
1793
		});
1804
		});
1794
1805
1795
		fTextWidget.addDisposeListener(
1806
		getTextWidget().addDisposeListener(
1796
			new DisposeListener() {
1807
			new DisposeListener() {
1797
				public void widgetDisposed(DisposeEvent e) {
1808
				public void widgetDisposed(DisposeEvent e) {
1798
					handleDispose();
1809
					handleDispose();
Lines 1800-1813 Link Here
1800
			}
1811
			}
1801
		);
1812
		);
1802
1813
1803
		fTextWidget.setFont(parent.getFont());
1814
		getTextWidget().setFont(parent.getFont());
1804
		fTextWidget.setDoubleClickEnabled(true);
1815
		getTextWidget().setDoubleClickEnabled(true);
1805
1816
1806
		/*
1817
		/*
1807
		 * Disable SWT Shift+TAB traversal in this viewer
1818
		 * Disable SWT Shift+TAB traversal in this viewer
1808
		 * 1GIYQ9K: ITPUI:WINNT - StyledText swallows Shift+TAB
1819
		 * 1GIYQ9K: ITPUI:WINNT - StyledText swallows Shift+TAB
1809
		 */
1820
		 */
1810
		fTextWidget.addTraverseListener(new TraverseListener() {
1821
		getTextWidget().addTraverseListener(new TraverseListener() {
1811
			public void keyTraversed(TraverseEvent e) {
1822
			public void keyTraversed(TraverseEvent e) {
1812
				if ((SWT.SHIFT == e.stateMask) && ('\t' == e.character))
1823
				if ((SWT.SHIFT == e.stateMask) && ('\t' == e.character))
1813
					e.doit= false;
1824
					e.doit= false;
Lines 1815-1826 Link Here
1815
		});
1826
		});
1816
1827
1817
		// where does the first line start
1828
		// where does the first line start
1818
		fTopInset= -fTextWidget.computeTrim(0, 0, 0, 0).y;
1829
		fTopInset= -getTextWidget().computeTrim(0, 0, 0, 0).y;
1819
1830
1820
		fVerifyListener.forward(true);
1831
		fVerifyListener.forward(true);
1821
		fTextWidget.addVerifyListener(fVerifyListener);
1832
		getTextWidget().addVerifyListener(fVerifyListener);
1822
1833
1823
		fTextWidget.addSelectionListener(new SelectionListener() {
1834
		getTextWidget().addSelectionListener(new SelectionListener() {
1824
			public void widgetDefaultSelected(SelectionEvent event) {
1835
			public void widgetDefaultSelected(SelectionEvent event) {
1825
				selectionChanged(event.x, event.y - event.x);
1836
				selectionChanged(event.x, event.y - event.x);
1826
			}
1837
			}
Lines 1839-1845 Link Here
1839
	 * @see Viewer#getControl()
1850
	 * @see Viewer#getControl()
1840
	 */
1851
	 */
1841
	public Control getControl() {
1852
	public Control getControl() {
1842
		return fTextWidget;
1853
		if (!is3270SupportRequired)
1854
			return fTextWidget;
1855
		return fField3270Widget;
1843
	}
1856
	}
1844
1857
1845
	/*
1858
	/*
Lines 1849-1856 Link Here
1849
1862
1850
		if (fDoubleClickStrategies != null && !fDoubleClickStrategies.isEmpty() && fDoubleClickStrategyConnector == null) {
1863
		if (fDoubleClickStrategies != null && !fDoubleClickStrategies.isEmpty() && fDoubleClickStrategyConnector == null) {
1851
			fDoubleClickStrategyConnector= new TextDoubleClickStrategyConnector();
1864
			fDoubleClickStrategyConnector= new TextDoubleClickStrategyConnector();
1852
			fTextWidget.addWordMovementListener(fDoubleClickStrategyConnector);
1865
			getTextWidget().addWordMovementListener(fDoubleClickStrategyConnector);
1853
			fTextWidget.addMouseListener(fDoubleClickStrategyConnector);
1866
			getTextWidget().addMouseListener(fDoubleClickStrategyConnector);
1854
		}
1867
		}
1855
1868
1856
		ensureHoverControlManagerInstalled();
1869
		ensureHoverControlManagerInstalled();
Lines 1977-1983 Link Here
1977
		fDocument= null;
1990
		fDocument= null;
1978
		fScroller= null;
1991
		fScroller= null;
1979
1992
1980
		fTextWidget= null;
1993
		fTextWidget = null;
1994
		fField3270Widget = null;
1981
	}
1995
	}
1982
1996
1983
1997
Lines 1987-1993 Link Here
1987
	 * @see org.eclipse.jface.text.ITextViewer#getTextWidget()
2001
	 * @see org.eclipse.jface.text.ITextViewer#getTextWidget()
1988
	 */
2002
	 */
1989
	public StyledText getTextWidget() {
2003
	public StyledText getTextWidget() {
1990
		return fTextWidget;
2004
		if (!is3270SupportRequired)
2005
			return fTextWidget;
2006
		return fField3270Widget.getStyledText();
1991
	}
2007
	}
1992
2008
1993
	/**
2009
	/**
Lines 2130-2146 Link Here
2130
	 * @see ITextViewer#isEditable()
2146
	 * @see ITextViewer#isEditable()
2131
	 */
2147
	 */
2132
	public boolean isEditable() {
2148
	public boolean isEditable() {
2133
		if (fTextWidget == null)
2149
		if (getTextWidget() == null)
2134
			return false;
2150
			return false;
2135
		return fTextWidget.getEditable();
2151
		return getTextWidget().getEditable();
2136
	}
2152
	}
2137
2153
2138
	/*
2154
	/*
2139
	 * @see ITextViewer#setEditable(boolean)
2155
	 * @see ITextViewer#setEditable(boolean)
2140
	 */
2156
	 */
2141
	public void setEditable(boolean editable) {
2157
	public void setEditable(boolean editable) {
2142
		if (fTextWidget != null)
2158
		if (getTextWidget() != null)
2143
			fTextWidget.setEditable(editable);
2159
			getTextWidget().setEditable(editable);
2144
	}
2160
	}
2145
2161
2146
	/*
2162
	/*
Lines 2290-2296 Link Here
2290
	 * @since 2.0
2306
	 * @since 2.0
2291
	 */
2307
	 */
2292
	 public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
2308
	 public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
2293
		 if (fTextWidget != null) {
2309
		 if (getTextWidget() != null) {
2294
			 if (fWidgetTokenKeeper != null) {
2310
			 if (fWidgetTokenKeeper != null) {
2295
				 if (fWidgetTokenKeeper == requester)
2311
				 if (fWidgetTokenKeeper == requester)
2296
					 return true;
2312
					 return true;
Lines 2311-2317 Link Here
2311
	 * @since 3.0
2327
	 * @since 3.0
2312
	 */
2328
	 */
2313
	public boolean requestWidgetToken(IWidgetTokenKeeper requester, int priority) {
2329
	public boolean requestWidgetToken(IWidgetTokenKeeper requester, int priority) {
2314
		if (fTextWidget != null) {
2330
		if (getTextWidget() != null) {
2315
			if (fWidgetTokenKeeper != null) {
2331
			if (fWidgetTokenKeeper != null) {
2316
2332
2317
				if (fWidgetTokenKeeper == requester)
2333
				if (fWidgetTokenKeeper == requester)
Lines 2358-2365 Link Here
2358
		if (!redraws() && fViewerState != null)
2374
		if (!redraws() && fViewerState != null)
2359
			return fViewerState.getSelection();
2375
			return fViewerState.getSelection();
2360
2376
2361
		if (fTextWidget != null) {
2377
		if (getTextWidget() != null) {
2362
			Point p= fTextWidget.getSelectionRange();
2378
			Point p= getTextWidget().getSelectionRange();
2363
			p= widgetSelection2ModelSelection(p);
2379
			p= widgetSelection2ModelSelection(p);
2364
			if (p != null)
2380
			if (p != null)
2365
				return p;
2381
				return p;
Lines 2379-2385 Link Here
2379
			return;
2395
			return;
2380
		}
2396
		}
2381
2397
2382
		if (fTextWidget == null)
2398
		if (getTextWidget() == null)
2383
			return;
2399
			return;
2384
2400
2385
		IRegion widgetSelection= modelRange2ClosestWidgetRange(new Region(selectionOffset, selectionLength));
2401
		IRegion widgetSelection= modelRange2ClosestWidgetRange(new Region(selectionOffset, selectionLength));
Lines 2388-2394 Link Here
2388
			int[] selectionRange= new int[] { widgetSelection.getOffset(), widgetSelection.getLength() };
2404
			int[] selectionRange= new int[] { widgetSelection.getOffset(), widgetSelection.getLength() };
2389
			validateSelectionRange(selectionRange);
2405
			validateSelectionRange(selectionRange);
2390
			if (selectionRange[0] >= 0) {
2406
			if (selectionRange[0] >= 0) {
2391
				fTextWidget.setSelectionRange(selectionRange[0], selectionRange[1]);
2407
				getTextWidget().setSelectionRange(selectionRange[0], selectionRange[1]);
2392
				selectionChanged(selectionRange[0], selectionRange[1]);
2408
				selectionChanged(selectionRange[0], selectionRange[1]);
2393
			}
2409
			}
2394
		}
2410
		}
Lines 2497-2515 Link Here
2497
				int startOffset= modelRange2ClosestWidgetRange(startRegion).getOffset();
2513
				int startOffset= modelRange2ClosestWidgetRange(startRegion).getOffset();
2498
				IRegion endRegion= new Region(endLineInfo.getOffset() + s.getEndColumn() - endVirtuals, 0);
2514
				IRegion endRegion= new Region(endLineInfo.getOffset() + s.getEndColumn() - endVirtuals, 0);
2499
				int endOffset= modelRange2ClosestWidgetRange(endRegion).getOffset();
2515
				int endOffset= modelRange2ClosestWidgetRange(endRegion).getOffset();
2500
				Point clientAreaOrigin= new Point(fTextWidget.getHorizontalPixel(), fTextWidget.getTopPixel());
2516
				Point clientAreaOrigin= new Point(getTextWidget().getHorizontalPixel(), getTextWidget().getTopPixel());
2501
				Point startLocation= Geometry.add(clientAreaOrigin, fTextWidget.getLocationAtOffset(startOffset));
2517
				Point startLocation= Geometry.add(clientAreaOrigin, getTextWidget().getLocationAtOffset(startOffset));
2502
				int averageCharWidth= getAverageCharWidth();
2518
				int averageCharWidth= getAverageCharWidth();
2503
				startLocation.x += startVirtuals * averageCharWidth;
2519
				startLocation.x += startVirtuals * averageCharWidth;
2504
				Point endLocation= Geometry.add(clientAreaOrigin, fTextWidget.getLocationAtOffset(endOffset));
2520
				Point endLocation= Geometry.add(clientAreaOrigin, getTextWidget().getLocationAtOffset(endOffset));
2505
				endLocation.x += endVirtuals * averageCharWidth;
2521
				endLocation.x += endVirtuals * averageCharWidth;
2506
				endLocation.y += fTextWidget.getLineHeight(endOffset);
2522
				endLocation.y += getTextWidget().getLineHeight(endOffset);
2507
2523
2508
				int widgetLength= endOffset - startOffset;
2524
				int widgetLength= endOffset - startOffset;
2509
				int[] widgetSelection= { startOffset, widgetLength};
2525
				int[] widgetSelection= { startOffset, widgetLength};
2510
				validateSelectionRange(widgetSelection);
2526
				validateSelectionRange(widgetSelection);
2511
				if (widgetSelection[0] >= 0) {
2527
				if (widgetSelection[0] >= 0) {
2512
					fTextWidget.setBlockSelectionBounds(Geometry.createRectangle(startLocation, Geometry.subtract(endLocation, startLocation)));
2528
					getTextWidget().setBlockSelectionBounds(Geometry.createRectangle(startLocation, Geometry.subtract(endLocation, startLocation)));
2513
					selectionChanged(startOffset, widgetLength);
2529
					selectionChanged(startOffset, widgetLength);
2514
				}
2530
				}
2515
			} catch (BadLocationException e) {
2531
			} catch (BadLocationException e) {
Lines 2530-2543 Link Here
2530
	 * @see Viewer#getSelection()
2546
	 * @see Viewer#getSelection()
2531
	 */
2547
	 */
2532
	public ISelection getSelection() {
2548
	public ISelection getSelection() {
2533
		if (fTextWidget != null && fTextWidget.getBlockSelection()) {
2549
		if (getTextWidget() != null && getTextWidget().getBlockSelection()) {
2534
			int[] ranges= fTextWidget.getSelectionRanges();
2550
			int[] ranges= getTextWidget().getSelectionRanges();
2535
			int startOffset= ranges[0];
2551
			int startOffset= ranges[0];
2536
			int endOffset= ranges[ranges.length - 2] + ranges[ranges.length - 1];
2552
			int endOffset= ranges[ranges.length - 2] + ranges[ranges.length - 1];
2537
			
2553
			
2538
			// getBlockSelectionBounds returns pixel coordinates relative to document
2554
			// getBlockSelectionBounds returns pixel coordinates relative to document
2539
			Rectangle bounds= fTextWidget.getBlockSelectionBounds();
2555
			Rectangle bounds= getTextWidget().getBlockSelectionBounds();
2540
			int clientAreaX= fTextWidget.getHorizontalPixel();
2556
			int clientAreaX= getTextWidget().getHorizontalPixel();
2541
			int startX= bounds.x - clientAreaX;
2557
			int startX= bounds.x - clientAreaX;
2542
			int endX= bounds.x + bounds.width - clientAreaX;
2558
			int endX= bounds.x + bounds.width - clientAreaX;
2543
			int avgCharWidth= getAverageCharWidth();
2559
			int avgCharWidth= getAverageCharWidth();
Lines 2559-2565 Link Here
2559
				int endColumn= endOffset - document.getLineOffset(endLine) + endVirtuals;
2575
				int endColumn= endOffset - document.getLineOffset(endLine) + endVirtuals;
2560
				if (startLine == -1 || endLine == -1)
2576
				if (startLine == -1 || endLine == -1)
2561
					return TextSelection.emptySelection();
2577
					return TextSelection.emptySelection();
2562
				return new BlockTextSelection(document, startLine, startColumn, endLine, endColumn, fTextWidget.getTabs());
2578
				return new BlockTextSelection(document, startLine, startColumn, endLine, endColumn, getTextWidget().getTabs());
2563
			} catch (BadLocationException e) {
2579
			} catch (BadLocationException e) {
2564
				return TextSelection.emptySelection();
2580
				return TextSelection.emptySelection();
2565
			}
2581
			}
Lines 2584-2590 Link Here
2584
	 * @since 3.5
2600
	 * @since 3.5
2585
	 */
2601
	 */
2586
	private int computeVirtualChars(int offset, int x, int avgCharWidth) {
2602
	private int computeVirtualChars(int offset, int x, int avgCharWidth) {
2587
		int diff= x - fTextWidget.getLocationAtOffset(offset).x;
2603
		int diff= x - getTextWidget().getLocationAtOffset(offset).x;
2588
		return diff > 0 ? diff / avgCharWidth : 0;
2604
		return diff > 0 ? diff / avgCharWidth : 0;
2589
	}
2605
	}
2590
2606
Lines 2632-2641 Link Here
2632
	 * @since 3.0
2648
	 * @since 3.0
2633
	 */
2649
	 */
2634
	private Display getDisplay() {
2650
	private Display getDisplay() {
2635
		if (fTextWidget == null || fTextWidget.isDisposed())
2651
		if (getTextWidget() == null || getTextWidget().isDisposed())
2636
			return null;
2652
			return null;
2637
2653
2638
		Display display= fTextWidget.getDisplay();
2654
		Display display= getTextWidget().getDisplay();
2639
		if (display != null && display.isDisposed())
2655
		if (display != null && display.isDisposed())
2640
			return null;
2656
			return null;
2641
2657
Lines 2660-2666 Link Here
2660
				if (id == fNumberOfPostSelectionChangedEvents[0]) {
2676
				if (id == fNumberOfPostSelectionChangedEvents[0]) {
2661
					// Check again because this is executed after the delay
2677
					// Check again because this is executed after the delay
2662
					if (getDisplay() != null)  {
2678
					if (getDisplay() != null)  {
2663
						Point selection= fTextWidget.getSelectionRange();
2679
						Point selection= getTextWidget().getSelectionRange();
2664
						if (selection != null) {
2680
						if (selection != null) {
2665
							IRegion r= widgetRange2ModelRange(new Region(selection.x, selection.y));
2681
							IRegion r= widgetRange2ModelRange(new Region(selection.x, selection.y));
2666
							if (fireEqualSelection || (r != null && !r.equals(fLastSentPostSelectionChange)) || r == null)  {
2682
							if (fireEqualSelection || (r != null && !r.equals(fLastSentPostSelectionChange)) || r == null)  {
Lines 3033-3047 Link Here
3033
		if (fViewportGuard != null)
3049
		if (fViewportGuard != null)
3034
			return;
3050
			return;
3035
3051
3036
		if (fTextWidget != null) {
3052
		if (getTextWidget() != null) {
3037
3053
3038
			fViewportGuard= new ViewportGuard();
3054
			fViewportGuard= new ViewportGuard();
3039
			fLastTopPixel= -1;
3055
			fLastTopPixel= -1;
3040
3056
3041
			fTextWidget.addKeyListener(fViewportGuard);
3057
			getTextWidget().addKeyListener(fViewportGuard);
3042
			fTextWidget.addMouseListener(fViewportGuard);
3058
			getTextWidget().addMouseListener(fViewportGuard);
3043
3059
3044
			fScroller= fTextWidget.getVerticalBar();
3060
			fScroller= getTextWidget().getVerticalBar();
3045
			if (fScroller != null)
3061
			if (fScroller != null)
3046
				fScroller.addSelectionListener(fViewportGuard);
3062
				fScroller.addSelectionListener(fViewportGuard);
3047
		}
3063
		}
Lines 3052-3061 Link Here
3052
	 */
3068
	 */
3053
	private void removeViewPortUpdate() {
3069
	private void removeViewPortUpdate() {
3054
3070
3055
		if (fTextWidget != null) {
3071
		if (getTextWidget() != null) {
3056
3072
3057
			fTextWidget.removeKeyListener(fViewportGuard);
3073
			getTextWidget().removeKeyListener(fViewportGuard);
3058
			fTextWidget.removeMouseListener(fViewportGuard);
3074
			getTextWidget().removeMouseListener(fViewportGuard);
3059
3075
3060
			if (fScroller != null && !fScroller.isDisposed()) {
3076
			if (fScroller != null && !fScroller.isDisposed()) {
3061
				fScroller.removeSelectionListener(fViewportGuard);
3077
				fScroller.removeSelectionListener(fViewportGuard);
Lines 3099-3105 Link Here
3099
	protected void updateViewportListeners(int origin) {
3115
	protected void updateViewportListeners(int origin) {
3100
3116
3101
		if (redraws()) {
3117
		if (redraws()) {
3102
			int topPixel= fTextWidget.getTopPixel();
3118
			int topPixel= getTextWidget().getTopPixel();
3103
			if (topPixel >= 0 && topPixel != fLastTopPixel) {
3119
			if (topPixel >= 0 && topPixel != fLastTopPixel) {
3104
				if (fViewportListeners != null) {
3120
				if (fViewportListeners != null) {
3105
					for (int i= 0; i < fViewportListeners.size(); i++) {
3121
					for (int i= 0; i < fViewportListeners.size(); i++) {
Lines 3119-3126 Link Here
3119
	 */
3135
	 */
3120
	public int getTopIndex() {
3136
	public int getTopIndex() {
3121
3137
3122
		if (fTextWidget != null) {
3138
		if (getTextWidget() != null) {
3123
			int top= fTextWidget.getTopIndex();
3139
			int top= getTextWidget().getTopIndex();
3124
			return widgetLine2ModelLine(top);
3140
			return widgetLine2ModelLine(top);
3125
		}
3141
		}
3126
3142
Lines 3132-3145 Link Here
3132
	 */
3148
	 */
3133
	public void setTopIndex(int index) {
3149
	public void setTopIndex(int index) {
3134
3150
3135
		if (fTextWidget != null) {
3151
		if (getTextWidget() != null) {
3136
3152
3137
			int widgetLine= modelLine2WidgetLine(index);
3153
			int widgetLine= modelLine2WidgetLine(index);
3138
			if (widgetLine == -1)
3154
			if (widgetLine == -1)
3139
				widgetLine= getClosestWidgetLineForModelLine(index);
3155
				widgetLine= getClosestWidgetLineForModelLine(index);
3140
3156
3141
			if (widgetLine > -1) {
3157
			if (widgetLine > -1) {
3142
				fTextWidget.setTopIndex(widgetLine);
3158
				getTextWidget().setTopIndex(widgetLine);
3143
					updateViewportListeners(INTERNAL);
3159
					updateViewportListeners(INTERNAL);
3144
			}
3160
			}
3145
		}
3161
		}
Lines 3156-3165 Link Here
3156
	 * @deprecated as of 3.2
3172
	 * @deprecated as of 3.2
3157
	 */
3173
	 */
3158
	protected int getVisibleLinesInViewport() {
3174
	protected int getVisibleLinesInViewport() {
3159
		if (fTextWidget != null) {
3175
		if (getTextWidget() != null) {
3160
			Rectangle clArea= fTextWidget.getClientArea();
3176
			Rectangle clArea= getTextWidget().getClientArea();
3161
			if (!clArea.isEmpty())
3177
			if (!clArea.isEmpty())
3162
				return clArea.height / fTextWidget.getLineHeight();
3178
				return clArea.height / getTextWidget().getLineHeight();
3163
		}
3179
		}
3164
		return -1;
3180
		return -1;
3165
	}
3181
	}
Lines 3169-3178 Link Here
3169
	 */
3185
	 */
3170
	public int getBottomIndex() {
3186
	public int getBottomIndex() {
3171
3187
3172
		if (fTextWidget == null)
3188
		if (getTextWidget() == null)
3173
			return -1;
3189
			return -1;
3174
3190
3175
		int widgetBottom= JFaceTextUtil.getBottomIndex(fTextWidget);
3191
		int widgetBottom= JFaceTextUtil.getBottomIndex(getTextWidget());
3176
		return widgetLine2ModelLine(widgetBottom);
3192
		return widgetLine2ModelLine(widgetBottom);
3177
	}
3193
	}
3178
3194
Lines 3181-3188 Link Here
3181
	 */
3197
	 */
3182
	public int getTopIndexStartOffset() {
3198
	public int getTopIndexStartOffset() {
3183
3199
3184
		if (fTextWidget != null) {
3200
		if (getTextWidget() != null) {
3185
			int top= fTextWidget.getTopIndex();
3201
			int top= getTextWidget().getTopIndex();
3186
			try {
3202
			try {
3187
				top= getVisibleDocument().getLineOffset(top);
3203
				top= getVisibleDocument().getLineOffset(top);
3188
				return widgetOffset2ModelOffset(top);
3204
				return widgetOffset2ModelOffset(top);
Lines 3223-3229 Link Here
3223
	 */
3239
	 */
3224
	public void revealRange(int start, int length) {
3240
	public void revealRange(int start, int length) {
3225
3241
3226
		if (fTextWidget == null || !redraws())
3242
		if (getTextWidget() == null || !redraws())
3227
			return;
3243
			return;
3228
3244
3229
		IRegion modelRange= new Region(start, length);
3245
		IRegion modelRange= new Region(start, length);
Lines 3258-3268 Link Here
3258
			int startLine= doc.getLineOfOffset(start);
3274
			int startLine= doc.getLineOfOffset(start);
3259
			int endLine= doc.getLineOfOffset(end);
3275
			int endLine= doc.getLineOfOffset(end);
3260
3276
3261
			int top= fTextWidget.getTopIndex();
3277
			int top= getTextWidget().getTopIndex();
3262
			if (top > -1) {
3278
			if (top > -1) {
3263
3279
3264
				// scroll vertically
3280
				// scroll vertically
3265
				int bottom= JFaceTextUtil.getBottomIndex(fTextWidget);
3281
				int bottom= JFaceTextUtil.getBottomIndex(getTextWidget());
3266
				int lines= bottom - top;
3282
				int lines= bottom - top;
3267
3283
3268
				// if the widget is not scrollable as it is displaying the entire content
3284
				// if the widget is not scrollable as it is displaying the entire content
Lines 3275-3281 Link Here
3275
				} else {
3291
				} else {
3276
3292
3277
					int delta= Math.max(0, lines - (endLine - startLine));
3293
					int delta= Math.max(0, lines - (endLine - startLine));
3278
					fTextWidget.setTopIndex(startLine - delta/3);
3294
					getTextWidget().setTopIndex(startLine - delta/3);
3279
					updateViewportListeners(INTERNAL);
3295
					updateViewportListeners(INTERNAL);
3280
				}
3296
				}
3281
3297
Lines 3293-3309 Link Here
3293
				if (endLine > startLine) {
3309
				if (endLine > startLine) {
3294
					// reveal the beginning of the range in the start line
3310
					// reveal the beginning of the range in the start line
3295
					IRegion extent= getExtent(start, start);
3311
					IRegion extent= getExtent(start, start);
3296
					startPixel= extent.getOffset() + fTextWidget.getHorizontalPixel();
3312
					startPixel= extent.getOffset() + getTextWidget().getHorizontalPixel();
3297
					endPixel= startPixel;
3313
					endPixel= startPixel;
3298
3314
3299
				} else {
3315
				} else {
3300
					IRegion extent= getExtent(start, end);
3316
					IRegion extent= getExtent(start, end);
3301
					startPixel= extent.getOffset() + fTextWidget.getHorizontalPixel();
3317
					startPixel= extent.getOffset() + getTextWidget().getHorizontalPixel();
3302
					endPixel= startPixel + extent.getLength();
3318
					endPixel= startPixel + extent.getLength();
3303
				}
3319
				}
3304
3320
3305
				int visibleStart= fTextWidget.getHorizontalPixel();
3321
				int visibleStart= getTextWidget().getHorizontalPixel();
3306
				int visibleEnd= visibleStart + fTextWidget.getClientArea().width;
3322
				int visibleEnd= visibleStart + getTextWidget().getClientArea().width;
3307
3323
3308
				// scroll only if not yet visible
3324
				// scroll only if not yet visible
3309
				if (startPixel < visibleStart || visibleEnd < endPixel) {
3325
				if (startPixel < visibleStart || visibleEnd < endPixel) {
Lines 3325-3331 Link Here
3325
3341
3326
					float index= ((float)newOffset) / ((float)getAverageCharWidth());
3342
					float index= ((float)newOffset) / ((float)getAverageCharWidth());
3327
3343
3328
					fTextWidget.setHorizontalIndex(Math.round(index));
3344
					getTextWidget().setHorizontalIndex(Math.round(index));
3329
				}
3345
				}
3330
3346
3331
			}
3347
			}
Lines 3342-3349 Link Here
3342
	 * @deprecated use <code>getWidthInPixels(int, int)</code> instead
3358
	 * @deprecated use <code>getWidthInPixels(int, int)</code> instead
3343
	 */
3359
	 */
3344
	final protected int getWidthInPixels(String text) {
3360
	final protected int getWidthInPixels(String text) {
3345
		GC gc= new GC(fTextWidget);
3361
		GC gc= new GC(getTextWidget());
3346
		gc.setFont(fTextWidget.getFont());
3362
		gc.setFont(getTextWidget().getFont());
3347
		Point extent= gc.textExtent(text);
3363
		Point extent= gc.textExtent(text);
3348
		gc.dispose();
3364
		gc.dispose();
3349
		return extent.x;
3365
		return extent.x;
Lines 3362-3372 Link Here
3362
	 */
3378
	 */
3363
	final protected IRegion getExtent(int start, int end) {
3379
	final protected IRegion getExtent(int start, int end) {
3364
		if (end > 0 && start < end) {
3380
		if (end > 0 && start < end) {
3365
			Rectangle bounds= fTextWidget.getTextBounds(start, end - 1);
3381
			Rectangle bounds= getTextWidget().getTextBounds(start, end - 1);
3366
			return new Region(bounds.x, bounds.width);
3382
			return new Region(bounds.x, bounds.width);
3367
		}
3383
		}
3368
3384
3369
		return new Region(fTextWidget.getLocationAtOffset(start).x, 0);
3385
		return new Region(getTextWidget().getLocationAtOffset(start).x, 0);
3370
	}
3386
	}
3371
3387
3372
	/**
3388
	/**
Lines 3470-3483 Link Here
3470
	 */
3486
	 */
3471
	private void initializeWidgetContents() {
3487
	private void initializeWidgetContents() {
3472
3488
3473
		if (fTextWidget != null && fVisibleDocument != null) {
3489
		if (getTextWidget() != null && fVisibleDocument != null) {
3474
3490
3475
			// set widget content
3491
			// set widget content
3476
			if (fDocumentAdapter == null)
3492
			if (fDocumentAdapter == null)
3477
				fDocumentAdapter= createDocumentAdapter();
3493
				fDocumentAdapter= createDocumentAdapter();
3478
3494
3479
			fDocumentAdapter.setDocument(fVisibleDocument);
3495
			fDocumentAdapter.setDocument(fVisibleDocument);
3480
			fTextWidget.setContent(fDocumentAdapter);
3496
			getTextWidget().setContent(fDocumentAdapter);
3481
3497
3482
			// invalidate presentation
3498
			// invalidate presentation
3483
			invalidateTextPresentation();
3499
			invalidateTextPresentation();
Lines 3761-3769 Link Here
3761
				return;
3777
				return;
3762
		}
3778
		}
3763
		
3779
		
3764
		if (fTextWidget.getBlockSelection() && (e.text == null || e.text.length() < 2)) {
3780
		if (getTextWidget().getBlockSelection() && (e.text == null || e.text.length() < 2)) {
3765
			Point sel = fTextWidget.getSelection();
3781
			Point sel = getTextWidget().getSelection();
3766
			if (fTextWidget.getLineAtOffset(sel.x) != fTextWidget.getLineAtOffset(sel.y)) {
3782
			if (getTextWidget().getLineAtOffset(sel.x) != getTextWidget().getLineAtOffset(sel.y)) {
3767
				verifyEventInBlockSelection(e);
3783
				verifyEventInBlockSelection(e);
3768
				return;
3784
				return;
3769
			}
3785
			}
Lines 3784-3790 Link Here
3784
3800
3785
				fDocumentCommand.execute(getDocument());
3801
				fDocumentCommand.execute(getDocument());
3786
3802
3787
				if (fTextWidget != null) {
3803
				if (getTextWidget() != null) {
3788
					int documentCaret= fDocumentCommand.caretOffset;
3804
					int documentCaret= fDocumentCommand.caretOffset;
3789
					if (documentCaret == -1) {
3805
					if (documentCaret == -1) {
3790
						// old behavior of document command
3806
						// old behavior of document command
Lines 3805-3814 Link Here
3805
3821
3806
					if (widgetCaret != -1) {
3822
					if (widgetCaret != -1) {
3807
						// there is a valid widget caret
3823
						// there is a valid widget caret
3808
						fTextWidget.setCaretOffset(widgetCaret);
3824
						getTextWidget().setCaretOffset(widgetCaret);
3809
					}
3825
					}
3810
3826
3811
					fTextWidget.showSelection();
3827
					getTextWidget().showSelection();
3812
				}
3828
				}
3813
			} catch (BadLocationException x) {
3829
			} catch (BadLocationException x) {
3814
3830
Lines 3889-3895 Link Here
3889
	 */
3905
	 */
3890
	private boolean isMarkedRegionEmpty() {
3906
	private boolean isMarkedRegionEmpty() {
3891
		return
3907
		return
3892
			fTextWidget == null ||
3908
			getTextWidget() == null ||
3893
			fMarkPosition == null ||
3909
			fMarkPosition == null ||
3894
			fMarkPosition.isDeleted() ||
3910
			fMarkPosition.isDeleted() ||
3895
			modelRange2WidgetRange(fMarkPosition) == null;
3911
			modelRange2WidgetRange(fMarkPosition) == null;
Lines 3900-3913 Link Here
3900
	 */
3916
	 */
3901
	public boolean canDoOperation(int operation) {
3917
	public boolean canDoOperation(int operation) {
3902
3918
3903
		if (fTextWidget == null || !redraws())
3919
		if (getTextWidget() == null || !redraws())
3904
			return false;
3920
			return false;
3905
3921
3906
		switch (operation) {
3922
		switch (operation) {
3907
			case CUT:
3923
			case CUT:
3908
				return isEditable() &&(fTextWidget.getSelectionCount() > 0 || !isMarkedRegionEmpty());
3924
				return isEditable() &&(getTextWidget().getSelectionCount() > 0 || !isMarkedRegionEmpty());
3909
			case COPY:
3925
			case COPY:
3910
				return fTextWidget.getSelectionCount() > 0 || !isMarkedRegionEmpty();
3926
				return getTextWidget().getSelectionCount() > 0 || !isMarkedRegionEmpty();
3911
			case DELETE:
3927
			case DELETE:
3912
			case PASTE:
3928
			case PASTE:
3913
				return isEditable();
3929
				return isEditable();
Lines 3935-3941 Link Here
3935
	 */
3951
	 */
3936
	public void doOperation(int operation) {
3952
	public void doOperation(int operation) {
3937
3953
3938
		if (fTextWidget == null || !redraws())
3954
		if (getTextWidget() == null || !redraws())
3939
			return;
3955
			return;
3940
3956
3941
		Point selection= null;
3957
		Point selection= null;
Lines 3957-3980 Link Here
3957
				}
3973
				}
3958
				break;
3974
				break;
3959
			case CUT:
3975
			case CUT:
3960
				if (fTextWidget.getSelectionCount() == 0)
3976
				if (getTextWidget().getSelectionCount() == 0)
3961
					copyMarkedRegion(true);
3977
					copyMarkedRegion(true);
3962
				else
3978
				else
3963
					wrapCompoundChange(new Runnable() {
3979
					wrapCompoundChange(new Runnable() {
3964
						public void run() {
3980
						public void run() {
3965
							fTextWidget.cut();
3981
							getTextWidget().cut();
3966
						}
3982
						}
3967
					});
3983
					});
3968
3984
3969
				selection= fTextWidget.getSelectionRange();
3985
				selection= getTextWidget().getSelectionRange();
3970
				fireSelectionChanged(selection.x, selection.y);
3986
				fireSelectionChanged(selection.x, selection.y);
3971
3987
3972
				break;
3988
				break;
3973
			case COPY:
3989
			case COPY:
3974
				if (fTextWidget.getSelectionCount() == 0)
3990
				if (getTextWidget().getSelectionCount() == 0)
3975
					copyMarkedRegion(false);
3991
					copyMarkedRegion(false);
3976
				else
3992
				else
3977
					fTextWidget.copy();
3993
					getTextWidget().copy();
3978
				break;
3994
				break;
3979
			case PASTE:
3995
			case PASTE:
3980
				paste();
3996
				paste();
Lines 3985-3993 Link Here
3985
			case SELECT_ALL: {
4001
			case SELECT_ALL: {
3986
				IDocument doc= getDocument();
4002
				IDocument doc= getDocument();
3987
				if (doc != null) {
4003
				if (doc != null) {
3988
					if (fTextWidget.getBlockSelection())
4004
					if (getTextWidget().getBlockSelection())
3989
						// XXX: performance hack: use 1000 for the endColumn - StyledText will not select more than what's possible in the viewport.
4005
						// XXX: performance hack: use 1000 for the endColumn - StyledText will not select more than what's possible in the viewport.
3990
						setSelection(new BlockTextSelection(doc, 0, 0, doc.getNumberOfLines() - 1, 1000, fTextWidget.getTabs()));
4006
						setSelection(new BlockTextSelection(doc, 0, 0, doc.getNumberOfLines() - 1, 1000, getTextWidget().getTabs()));
3991
					else
4007
					else
3992
						setSelectedRange(0, doc.getLength());
4008
						setSelectedRange(0, doc.getLength());
3993
				}
4009
				}
Lines 4012-4019 Link Here
4012
	}
4028
	}
4013
4029
4014
	private void delete() {
4030
	private void delete() {
4015
		if (!fTextWidget.getBlockSelection()) {
4031
		if (!getTextWidget().getBlockSelection()) {
4016
			fTextWidget.invokeAction(ST.DELETE_NEXT);
4032
			getTextWidget().invokeAction(ST.DELETE_NEXT);
4017
		} else {
4033
		} else {
4018
			wrapCompoundChange(new Runnable(){
4034
			wrapCompoundChange(new Runnable(){
4019
				public void run() {
4035
				public void run() {
Lines 4026-4039 Link Here
4026
				}
4042
				}
4027
			});
4043
			});
4028
		}
4044
		}
4029
		Point selection= fTextWidget.getSelectionRange();
4045
		Point selection= getTextWidget().getSelectionRange();
4030
		fireSelectionChanged(selection.x, selection.y);
4046
		fireSelectionChanged(selection.x, selection.y);
4031
	}
4047
	}
4032
4048
4033
	private void paste() {
4049
	private void paste() {
4034
//		ignoreAutoEditStrategies(true);
4050
//		ignoreAutoEditStrategies(true);
4035
		if (!fTextWidget.getBlockSelection()) {
4051
		if (!getTextWidget().getBlockSelection()) {
4036
			fTextWidget.paste();
4052
			getTextWidget().paste();
4037
		} else {
4053
		} else {
4038
			wrapCompoundChange(new Runnable(){
4054
			wrapCompoundChange(new Runnable(){
4039
				public void run() {
4055
				public void run() {
Lines 4082-4088 Link Here
4082
				}
4098
				}
4083
			});
4099
			});
4084
		}
4100
		}
4085
		Point selection= fTextWidget.getSelectionRange();
4101
		Point selection= getTextWidget().getSelectionRange();
4086
		fireSelectionChanged(selection.x, selection.y);
4102
		fireSelectionChanged(selection.x, selection.y);
4087
//		ignoreAutoEditStrategies(false);
4103
//		ignoreAutoEditStrategies(false);
4088
	}
4104
	}
Lines 4097-4103 Link Here
4097
	 * @since 3.5
4113
	 * @since 3.5
4098
	 */
4114
	 */
4099
	private void wrapCompoundChange(Runnable runnable) {
4115
	private void wrapCompoundChange(Runnable runnable) {
4100
		if (!fTextWidget.getBlockSelection()) {
4116
		if (!getTextWidget().getBlockSelection()) {
4101
			runnable.run();
4117
			runnable.run();
4102
			return;
4118
			return;
4103
		}
4119
		}
Lines 4162-4189 Link Here
4162
	 */
4178
	 */
4163
	protected void copyMarkedRegion(boolean delete) {
4179
	protected void copyMarkedRegion(boolean delete) {
4164
4180
4165
		if (fTextWidget == null)
4181
		if (getTextWidget() == null)
4166
			return;
4182
			return;
4167
4183
4168
		if (fMarkPosition == null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) == null)
4184
		if (fMarkPosition == null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) == null)
4169
			return;
4185
			return;
4170
4186
4171
		int widgetMarkOffset= modelOffset2WidgetOffset(fMarkPosition.offset);
4187
		int widgetMarkOffset= modelOffset2WidgetOffset(fMarkPosition.offset);
4172
		Point selection= fTextWidget.getSelection();
4188
		Point selection= getTextWidget().getSelection();
4173
		if (selection.x <= widgetMarkOffset)
4189
		if (selection.x <= widgetMarkOffset)
4174
			fTextWidget.setSelection(selection.x, widgetMarkOffset);
4190
			getTextWidget().setSelection(selection.x, widgetMarkOffset);
4175
		else
4191
		else
4176
			fTextWidget.setSelection(widgetMarkOffset, selection.x);
4192
			getTextWidget().setSelection(widgetMarkOffset, selection.x);
4177
4193
4178
		if (delete) {
4194
		if (delete) {
4179
			wrapCompoundChange(new Runnable() {
4195
			wrapCompoundChange(new Runnable() {
4180
				public void run() {
4196
				public void run() {
4181
					fTextWidget.cut();
4197
					getTextWidget().cut();
4182
				}
4198
				}
4183
			});
4199
			});
4184
		} else {
4200
		} else {
4185
			fTextWidget.copy();
4201
			getTextWidget().copy();
4186
			fTextWidget.setSelection(selection.x); // restore old cursor position
4202
			getTextWidget().setSelection(selection.x); // restore old cursor position
4187
		}
4203
		}
4188
	}
4204
	}
4189
4205
Lines 4195-4201 Link Here
4195
	 * @deprecated use <code>StyledText.invokeAction</code> instead
4211
	 * @deprecated use <code>StyledText.invokeAction</code> instead
4196
	 */
4212
	 */
4197
	protected void deleteText() {
4213
	protected void deleteText() {
4198
		fTextWidget.invokeAction(ST.DELETE_NEXT);
4214
		getTextWidget().invokeAction(ST.DELETE_NEXT);
4199
	}
4215
	}
4200
4216
4201
	/**
4217
	/**
Lines 4502-4508 Link Here
4502
	 * @since 3.4
4518
	 * @since 3.4
4503
	 */
4519
	 */
4504
	public void print(StyledTextPrintOptions options) {
4520
	public void print(StyledTextPrintOptions options) {
4505
		final Shell shell= fTextWidget.getShell();
4521
		final Shell shell= getTextWidget().getShell();
4506
4522
4507
		if (Printer.getPrinterList().length == 0) {
4523
		if (Printer.getPrinterList().length == 0) {
4508
			String title= JFaceTextMessages.getString("TextViewer.warning.noPrinter.title"); //$NON-NLS-1$
4524
			String title= JFaceTextMessages.getString("TextViewer.warning.noPrinter.title"); //$NON-NLS-1$
Lines 4517-4523 Link Here
4517
4533
4518
		if (data != null) {
4534
		if (data != null) {
4519
			final Printer printer= new Printer(data);
4535
			final Printer printer= new Printer(data);
4520
			final Runnable styledTextPrinter= fTextWidget.print(printer, options);
4536
			final Runnable styledTextPrinter= getTextWidget().print(printer, options);
4521
4537
4522
			Thread printingThread= new Thread("Printing") { //$NON-NLS-1$
4538
			Thread printingThread= new Thread("Printing") { //$NON-NLS-1$
4523
				public void run() {
4539
				public void run() {
Lines 4561-4567 Link Here
4561
	 */
4577
	 */
4562
	protected boolean canPerformFind() {
4578
	protected boolean canPerformFind() {
4563
		IDocument d= getVisibleDocument();
4579
		IDocument d= getVisibleDocument();
4564
		return (fTextWidget != null && d != null && d.getLength() > 0);
4580
		return (getTextWidget() != null && d != null && d.getLength() > 0);
4565
	}
4581
	}
4566
4582
4567
	/**
4583
	/**
Lines 4599-4605 Link Here
4599
	 *
4615
	 *
4600
	 */
4616
	 */
4601
	protected int findAndSelect(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
4617
	protected int findAndSelect(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
4602
		if (fTextWidget == null)
4618
		if (getTextWidget() == null)
4603
			return -1;
4619
			return -1;
4604
4620
4605
		try {
4621
		try {
Lines 4620-4626 Link Here
4620
					setRedraw(false);
4636
					setRedraw(false);
4621
4637
4622
				if (redraws()) {
4638
				if (redraws()) {
4623
					fTextWidget.setSelectionRange(widgetPos, length);
4639
					getTextWidget().setSelectionRange(widgetPos, length);
4624
					internalRevealRange(widgetPos, widgetPos + length);
4640
					internalRevealRange(widgetPos, widgetPos + length);
4625
					selectionChanged(widgetPos, length);
4641
					selectionChanged(widgetPos, length);
4626
				} else {
4642
				} else {
Lines 4655-4661 Link Here
4655
	 * @since 3.0
4671
	 * @since 3.0
4656
	 */
4672
	 */
4657
	protected int findAndSelectInRange(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, int rangeOffset, int rangeLength, boolean regExSearch) {
4673
	protected int findAndSelectInRange(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, int rangeOffset, int rangeLength, boolean regExSearch) {
4658
		if (fTextWidget == null)
4674
		if (getTextWidget() == null)
4659
			return -1;
4675
			return -1;
4660
4676
4661
		try {
4677
		try {
Lines 4697-4703 Link Here
4697
					setRedraw(false);
4713
					setRedraw(false);
4698
4714
4699
				if (redraws()) {
4715
				if (redraws()) {
4700
					fTextWidget.setSelectionRange(widgetPos, length);
4716
					getTextWidget().setSelectionRange(widgetPos, length);
4701
					internalRevealRange(widgetPos, widgetPos + length);
4717
					internalRevealRange(widgetPos, widgetPos + length);
4702
					selectionChanged(widgetPos, length);
4718
					selectionChanged(widgetPos, length);
4703
				} else {
4719
				} else {
Lines 4732-4738 Link Here
4732
	 * @see ITextViewer#setTextColor(Color, start, length, boolean)
4748
	 * @see ITextViewer#setTextColor(Color, start, length, boolean)
4733
	 */
4749
	 */
4734
	public void setTextColor(Color color, int start, int length, boolean controlRedraw) {
4750
	public void setTextColor(Color color, int start, int length, boolean controlRedraw) {
4735
		if (fTextWidget != null) {
4751
		if (getTextWidget() != null) {
4736
4752
4737
			StyleRange s= new StyleRange();
4753
			StyleRange s= new StyleRange();
4738
			s.foreground= color;
4754
			s.foreground= color;
Lines 4742-4753 Link Here
4742
			s= modelStyleRange2WidgetStyleRange(s);
4758
			s= modelStyleRange2WidgetStyleRange(s);
4743
			if (s != null) {
4759
			if (s != null) {
4744
				if (controlRedraw)
4760
				if (controlRedraw)
4745
					fTextWidget.setRedraw(false);
4761
					getTextWidget().setRedraw(false);
4746
				try {
4762
				try {
4747
					fTextWidget.setStyleRange(s);
4763
					getTextWidget().setStyleRange(s);
4748
				} finally {
4764
				} finally {
4749
					if (controlRedraw)
4765
					if (controlRedraw)
4750
						fTextWidget.setRedraw(true);
4766
						getTextWidget().setRedraw(true);
4751
				}
4767
				}
4752
			}
4768
			}
4753
		}
4769
		}
Lines 4765-4771 Link Here
4765
4781
4766
			range= modelStyleRange2WidgetStyleRange(range);
4782
			range= modelStyleRange2WidgetStyleRange(range);
4767
			if (range != null)
4783
			if (range != null)
4768
				fTextWidget.setStyleRange(range);
4784
				getTextWidget().setStyleRange(range);
4769
4785
4770
			ArrayList ranges= new ArrayList(presentation.getDenumerableRanges());
4786
			ArrayList ranges= new ArrayList(presentation.getDenumerableRanges());
4771
			Iterator e= presentation.getNonDefaultStyleRangeIterator();
4787
			Iterator e= presentation.getNonDefaultStyleRangeIterator();
Lines 4777-4783 Link Here
4777
			}
4793
			}
4778
4794
4779
			if (!ranges.isEmpty())
4795
			if (!ranges.isEmpty())
4780
				fTextWidget.replaceStyleRanges(0, 0, (StyleRange[])ranges.toArray(new StyleRange[ranges.size()]));
4796
				getTextWidget().replaceStyleRanges(0, 0, (StyleRange[])ranges.toArray(new StyleRange[ranges.size()]));
4781
4797
4782
		} else {
4798
		} else {
4783
			IRegion region= modelRange2WidgetRange(presentation.getCoverage());
4799
			IRegion region= modelRange2WidgetRange(presentation.getCoverage());
Lines 4796-4802 Link Here
4796
			if (!list.isEmpty()) {
4812
			if (!list.isEmpty()) {
4797
				StyleRange[] ranges= new StyleRange[list.size()];
4813
				StyleRange[] ranges= new StyleRange[list.size()];
4798
				list.toArray(ranges);
4814
				list.toArray(ranges);
4799
				fTextWidget.replaceStyleRanges(region.getOffset(), region.getLength(), ranges);
4815
				getTextWidget().replaceStyleRanges(region.getOffset(), region.getLength(), ranges);
4800
			}
4816
			}
4801
		}
4817
		}
4802
	}
4818
	}
Lines 4821-4827 Link Here
4821
		if (!list.isEmpty()) {
4837
		if (!list.isEmpty()) {
4822
			StyleRange[] ranges= new StyleRange[list.size()];
4838
			StyleRange[] ranges= new StyleRange[list.size()];
4823
			list.toArray(ranges);
4839
			list.toArray(ranges);
4824
			fTextWidget.setStyleRanges(ranges);
4840
			getTextWidget().setStyleRanges(ranges);
4825
		}
4841
		}
4826
	}
4842
	}
4827
4843
Lines 4850-4856 Link Here
4850
		if (presentation == null || !redraws())
4866
		if (presentation == null || !redraws())
4851
			return;
4867
			return;
4852
4868
4853
		if (fTextWidget == null)
4869
		if (getTextWidget() == null)
4854
			return;
4870
			return;
4855
4871
4856
4872
Lines 4870-4876 Link Here
4870
			return;
4886
			return;
4871
4887
4872
		if (controlRedraw)
4888
		if (controlRedraw)
4873
			fTextWidget.setRedraw(false);
4889
			getTextWidget().setRedraw(false);
4874
4890
4875
		if (fReplaceTextPresentation)
4891
		if (fReplaceTextPresentation)
4876
			applyTextPresentation(presentation);
4892
			applyTextPresentation(presentation);
Lines 4878-4884 Link Here
4878
			addPresentation(presentation);
4894
			addPresentation(presentation);
4879
4895
4880
		if (controlRedraw)
4896
		if (controlRedraw)
4881
			fTextWidget.setRedraw(true);
4897
			getTextWidget().setRedraw(true);
4882
	}
4898
	}
4883
4899
4884
	/*
4900
	/*
Lines 5079-5086 Link Here
5079
			fViewerState= null;
5095
			fViewerState= null;
5080
		}
5096
		}
5081
5097
5082
		if (fTextWidget != null && !fTextWidget.isDisposed())
5098
		if (getTextWidget() != null && !getTextWidget().isDisposed())
5083
			fTextWidget.setRedraw(true);
5099
			getTextWidget().setRedraw(true);
5084
5100
5085
		fireRedrawChanged();
5101
		fireRedrawChanged();
5086
	}
5102
	}
Lines 5098-5105 Link Here
5098
			extension.stopForwardingDocumentChanges();
5114
			extension.stopForwardingDocumentChanges();
5099
		}
5115
		}
5100
5116
5101
		if (fTextWidget != null && !fTextWidget.isDisposed())
5117
		if (getTextWidget() != null && !getTextWidget().isDisposed())
5102
			fTextWidget.setRedraw(false);
5118
			getTextWidget().setRedraw(false);
5103
5119
5104
		fireRedrawChanged();
5120
		fireRedrawChanged();
5105
	}
5121
	}
Lines 5724-5728 Link Here
5724
	public void setTabsToSpacesConverter(IAutoEditStrategy converter) {
5740
	public void setTabsToSpacesConverter(IAutoEditStrategy converter) {
5725
		fTabsToSpacesConverter= converter;
5741
		fTabsToSpacesConverter= converter;
5726
	}
5742
	}
5743
	
5744
    public void setIs3270SupportRequired(boolean b){
5745
    	this.is3270SupportRequired = b;
5746
    }
5747
5727
5748
5728
}
5749
}

Return to bug 298392