diff options
author | Sravan Kumar Lakkimsetti | 2017-11-29 06:46:52 +0000 |
---|---|---|
committer | Sravan Kumar Lakkimsetti | 2018-02-14 08:28:16 +0000 |
commit | 8e6c786f24d18aae455461982669263ba909ce1f (patch) | |
tree | 081d3ba88320dcb44ac5e832e232050d3066a0cd | |
parent | 453835051584dfb9db2a5524c52161d72dd95f93 (diff) | |
download | eclipse.platform.swt-8e6c786f24d18aae455461982669263ba909ce1f.tar.gz eclipse.platform.swt-8e6c786f24d18aae455461982669263ba909ce1f.tar.xz eclipse.platform.swt-8e6c786f24d18aae455461982669263ba909ce1f.zip |
Bug 519015 - Tab after 4 spaces is not visible
Change-Id: Ibe69a8fd115d6691550f8657d79dd8e4757d8b23
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
4 files changed, 110 insertions, 5 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java index ae4cee820b..f0ae01efd4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -30,6 +30,7 @@ class StyledTextRenderer { int tabWidth; int ascent, descent; int averageCharWidth; + int tabLength; //tab length in spaces /* Line data */ int topIndex = -1; @@ -883,6 +884,7 @@ TextLayout getTextLayout(int lineIndex, int orientation, int width, int lineSpac layout.setWidth(width); layout.setSpacing(lineSpacing); layout.setTabs(tabs); + layout.setDefaultTabWidth(tabLength); layout.setIndent(indent); layout.setWrapIndent(wrapIndent); layout.setAlignment(alignment); @@ -1084,6 +1086,7 @@ void setContent(StyledTextContent content) { void setFont(Font font, int tabs) { TextLayout layout = new TextLayout(device); layout.setFont(regularFont); + tabLength = tabs; if (font != null) { if (boldFont != null) boldFont.dispose(); if (italicFont != null) italicFont.dispose(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/TextLayout.java index 0a6ef50216..5788d2e047 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/TextLayout.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/TextLayout.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -50,6 +50,7 @@ public final class TextLayout extends Resource { char[] segmentsChars; int wrapWidth; int orientation; + private double defaultTabWidth; int[] lineOffsets; NSRect[] lineBounds; @@ -184,7 +185,18 @@ void computeRuns() { if (tabs != null && tabs.length > 0) { int count = tabs.length; if (count == 1) { - paragraph.setDefaultTabInterval(tabs[0]); + /** + * defaultTabWidth holds the tabstop in points. There are two conditions + * we need to consider if this value is 0 we need to use tabstop from + * tabs[]. Also in case of user setting only one tabstop we need to use + * the values from tab[] this can be determined by comparing tab[0] with + * defaultTabWidth + */ + double tabWidth = defaultTabWidth; + if (defaultTabWidth == 0 || Math.ceil(defaultTabWidth) != tabs[0]) { + tabWidth = tabs[0]; + } + paragraph.setDefaultTabInterval(tabWidth); } else { int i, pos = 0; for (i = 0; i < count; i++) { @@ -2284,4 +2296,51 @@ int untranslateOffset (int offset) { return offset; } +/** + * Sets Default Tab Width in terms if number of space characters. + * + * @param tabLength in number of characters + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the tabLength is less than <code>0</code></li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @noreference This method is not intended to be referenced by clients. + * + * DO NOT USE This might be removed in 4.8 + * + * @since 3.107 + */ +public void setDefaultTabWidth(int tabLength) { + + if (tabLength < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + + checkLayout(); + String oldString = getText(); + StringBuffer tabBuffer = new StringBuffer(tabLength); + for (int i = 0; i < tabLength; i++) { + tabBuffer.append(' '); + } + setText(tabBuffer.toString()); + this.defaultTabWidth = this.getTabWidth(); + setText (oldString); +} + +double getTabWidth() { + NSAutoreleasePool pool = null; + if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); + try { + computeRuns(); + NSRect rect = layoutManager.usedRectForTextContainer(textContainer); + if (wrapWidth != -1) rect.width = wrapWidth; + return rect.width; + } finally { + if (pool != null) pool.release(); + } +} + + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java index 156f878ba1..bfdfe24c54 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -2346,4 +2346,26 @@ int width () { return w[0]; } +/** + * Sets Default Tab Width in terms if number of space characters. + * + * @param tabLength in number of characters + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the tabLength is less than <code>0</code></li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @noreference This method is not intended to be referenced by clients. + * + * DO NOT USE This might be removed in 4.8 + * + * @since 3.107 + */ +public void setDefaultTabWidth(int tabLength) { + //unused in GTK +} + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java index 011b443883..0d00271b5d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -3692,4 +3692,25 @@ int untranslateOffset(int offset) { } return offset; } + +/** + * Sets Default Tab Width in terms if number of space characters. + * + * @param tabLength in number of characters + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the tabLength is less than <code>0</code></li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @noreference This method is not intended to be referenced by clients. + * + * DO NOT USE This might be removed in 4.8 + * @since 3.107 + */ +public void setDefaultTabWidth(int tabLength) { + // unused in win32 +} } |