Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java18
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java40
2 files changed, 54 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java
index 0e4bb56940..04e4064866 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java
@@ -50,6 +50,16 @@ public class TextStyle {
*/
public Color background;
+ /**
+ * the underline flag of the style
+ */
+ public boolean underline;
+
+ /**
+ * the strikeout flag of the style
+ */
+ public boolean strikeout;
+
/**
* Create a new text style with the specified font, foreground
* and background.
@@ -80,7 +90,9 @@ public boolean equals(Object object) {
} else if (style.background != null) return false;
if (this.font != null) {
if (!this.font.equals(style.font)) return false;
- } else if (style.font != null) return false;
+ } else if (style.font != null) return false;
+ if (this.underline != style.underline) return false;
+ if (this.strikeout != style.strikeout) return false;
return true;
}
@@ -89,6 +101,8 @@ public int hashCode() {
if (font != null) hash ^= font.hashCode();
if (foreground != null) hash ^= foreground.hashCode();
if (background != null) hash ^= background.hashCode();
+ if (underline) hash ^= hash;
+ if (strikeout) hash ^= hash;
return hash;
}
@@ -99,7 +113,7 @@ public int hashCode() {
* @return a string representation of the <code>RGB</code>
*/
public String toString () {
- return "TextStyle {font: " + font + ", foreground: " + foreground + ", background: " + background + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ return "TextStyle {font: " + font + ", foreground: " + foreground + ", background: " + background + ", underline: " + underline + ", strikeout: " + strikeout + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
}
}
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 1bc5c0e0d1..9784574e11 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
@@ -80,6 +80,7 @@ public final class TextLayout {
int width;
int ascent;
int descent;
+ int leading;
/* ScriptBreak */
int psla;
@@ -445,8 +446,11 @@ public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Col
int foreground = OS.GetTextColor(hdc);
int state = OS.SaveDC(hdc);
RECT rect = new RECT();
- int selBrush = 0;
- if (hasSelection) selBrush = OS.CreateSolidBrush (selectionBackground.handle);
+ int selBrush = 0, selPen = 0;
+ if (hasSelection) {
+ selBrush = OS.CreateSolidBrush(selectionBackground.handle);
+ selPen = OS.CreatePen(OS.BS_SOLID, 1, selectionForeground.handle);
+ }
int rop2 = 0;
if (OS.IsWinCE) {
rop2 = OS.SetROP2(hdc, OS.R2_COPYPEN);
@@ -537,6 +541,22 @@ public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Col
OS.SelectObject(hdc, getItemFont(run));
int drawRunY = drawY + (baseline - run.ascent);
OS.ScriptTextOut(hdc, run.psc, drawX, drawRunY, 0, null, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, null, run.goffsets);
+ if ((run.style != null) && (run.style.underline || run.style.strikeout)) {
+ int newPen = fg == selectionForeground.handle ? selPen : OS.CreatePen(OS.BS_SOLID, 1, fg);
+ int oldPen = OS.SelectObject(hdc, newPen);
+ if (run.style.underline) {
+ int underlineY = drawY + baseline + 1;
+ OS.MoveToEx(hdc, drawX, underlineY, 0);
+ OS.LineTo(hdc, drawX + run.width, underlineY);
+ }
+ if (run.style.strikeout) {
+ int strikeoutY = drawRunY + run.leading + run.ascent / 2;
+ OS.MoveToEx(hdc, drawX, strikeoutY, 0);
+ OS.LineTo(hdc, drawX + run.width, strikeoutY);
+ }
+ OS.SelectObject(hdc, oldPen);
+ if (fg != selectionForeground.handle) OS.DeleteObject(newPen);
+ }
boolean partialSelection = hasSelection && !(selectionStart > end || run.start > selectionEnd);
if (!fullSelection && partialSelection && fg != selectionForeground.handle) {
OS.SetTextColor(hdc, selectionForeground.handle);
@@ -554,6 +574,20 @@ public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Col
rect.right = drawX + runX;
rect.bottom = drawY + lineHeight;
OS.ScriptTextOut(hdc, run.psc, drawX, drawRunY, OS.ETO_CLIPPED, rect, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, null, run.goffsets);
+ if ((run.style != null) && (run.style.underline || run.style.strikeout)) {
+ int oldPen = OS.SelectObject(hdc, selPen);
+ if (run.style.underline) {
+ int underlineY = drawY + baseline + 1;
+ OS.MoveToEx(hdc, rect.left, underlineY, 0);
+ OS.LineTo(hdc, rect.right, underlineY);
+ }
+ if (run.style.strikeout) {
+ int strikeoutY = drawRunY + run.leading + run.ascent / 2;
+ OS.MoveToEx(hdc, rect.left, strikeoutY, 0);
+ OS.LineTo(hdc, rect.right, strikeoutY);
+ }
+ OS.SelectObject(hdc, oldPen);
+ }
}
}
}
@@ -562,6 +596,7 @@ public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Col
}
OS.RestoreDC(hdc, state);
if (selBrush != 0) OS.DeleteObject (selBrush);
+ if (selPen != 0) OS.DeleteObject (selPen);
}
void freeRuns () {
@@ -1903,6 +1938,7 @@ void shape (final int hdc, final StyleItem run) {
OS.GetTextMetrics(hdc, lptm);
run.ascent = lptm.tmAscent;
run.descent = lptm.tmDescent;
+ run.leading = lptm.tmInternalLeading;
}
int validadeOffset(int offset, int step) {

Back to the top