# HG changeset patch # User Frank Benoit # Date 1199694310 -3600 # Node ID b5521a2c27c2b1bb2281c1b32af6775928d7a594 # Parent 4f9c0fea3440948f76f751658618720ef9bedfaf TextStyle diff -r 4f9c0fea3440 -r b5521a2c27c2 dwt/graphics/Color.d --- a/dwt/graphics/Color.d Mon Jan 07 09:11:15 2008 +0100 +++ b/dwt/graphics/Color.d Mon Jan 07 09:25:10 2008 +0100 @@ -144,7 +144,7 @@ * * @see #hashCode */ -public int opEquals(Object object) { +public override int opEquals(Object object) { if (object is this) return true; if ( auto color = cast(Color)object ){ GdkColor* gdkColor = color.handle; @@ -207,7 +207,7 @@ * * @see #equals */ -public int hashCode() { +public override hash_t toHash() { if (isDisposed()) return 0; return handle.red ^ handle.green ^ handle.blue; } diff -r 4f9c0fea3440 -r b5521a2c27c2 dwt/graphics/TextStyle.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/graphics/TextStyle.d Mon Jan 07 09:25:10 2008 +0100 @@ -0,0 +1,201 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 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 + *******************************************************************************/ +module dwt.graphics.TextStyle; + +import dwt.SWT; +import dwt.graphics.Font; +import dwt.graphics.Color; +import dwt.graphics.GlyphMetrics; + +import tango.util.Convert; +/** + * TextStyle defines a set of styles that can be applied + * to a range of text. + *

+ * The hashCode() method in this class uses the values of the public + * fields to compute the hash value. When storing instances of the + * class in hashed collections, do not modify these fields after the + * object has been inserted. + *

+ *

+ * Application code does not need to explicitly release the + * resources managed by each instance when those instances are no longer + * required, and thus no dispose() method is provided. + *

+ * + * @see TextLayout + * @see Font + * @see Color + * + * @since 3.0 + */ +public class TextStyle { + + /** + * the font of the style + */ + public Font font; + + /** + * the foreground of the style + */ + public Color foreground; + + /** + * the background of the style + */ + public Color background; + + /** + * the underline flag of the style + * + * @since 3.1 + */ + public bool underline; + + /** + * the strikeout flag of the style + * + * @since 3.1 + */ + public bool strikeout; + + /** + * the GlyphMetrics of the style + * + * @since 3.2 + */ + public GlyphMetrics metrics; + + /** + * the baseline rise of the style. + * + * @since 3.2 + */ + public int rise; + +/** + * Create a new text style with the specified font, foreground + * and background. + * + * @param font the font of the style, null if none + * @param foreground the foreground color of the style, null if none + * @param background the background color of the style, null if none + */ +public this (Font font, Color foreground, Color background) { + if (font !is null && font.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); + if (foreground !is null && foreground.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); + if (background !is null && background.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); + this.font = font; + this.foreground = foreground; + this.background = background; +} + +/** + * Compares the argument to the receiver, and returns true + * if they represent the same object using a class + * specific comparison. + * + * @param object the object to compare with this object + * @return true if the object is the same as this object and false otherwise + * + * @see #hashCode() + */ +public override int opEquals(Object object) { + if (object is this) return true; + if (object is null) return false; + if (!(cast(TextStyle)object)) return false; + TextStyle style = cast(TextStyle)object; + if (foreground !is null) { + if ( foreground != style.foreground ) return false; + } else if (style.foreground !is null) return false; + if (background !is null) { + if ( background != style.background ) return false; + } else if (style.background !is null) return false; + if (font !is null) { + if (font != style.font) return false; + } else if (style.font != null) return false; + if (metrics != null || style.metrics !is null) return false; + if (underline !is style.underline) return false; + if (strikeout !is style.strikeout) return false; + if (rise !is style.rise) return false; + return true; +} + +/** + * Returns an integer hash code for the receiver. Any two + * objects that return true when passed to + * equals must return the same value for this + * method. + * + * @return the receiver's hash + * + * @see #equals(Object) + */ +public override hash_t toHash() { + int hash = 0; + if (foreground !is null) hash ^= foreground.toHash(); + if (background !is null) hash ^= background.toHash(); + if (font !is null) hash ^= font.toHash(); + if (metrics !is null) hash ^= metrics.toHash(); + if (underline) hash ^= hash; + if (strikeout) hash ^= hash; + hash ^= rise; + return hash; +} + +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the TextStyle + */ +public char[] toString () { + char[] buffer = "TextStyle {"; + int startLength = buffer.length; + if (font != null) { + if (buffer.length > startLength) buffer ~= ", "; + buffer ~= "font="; + buffer ~= font.toString; + } + if (foreground != null) { + if (buffer.length > startLength) buffer ~= ", "; + buffer ~= "foreground="; + buffer ~= foreground.toString; + } + if (background != null) { + if (buffer.length > startLength) buffer ~= ", "; + buffer ~= "background="; + buffer ~= background.toString; + } + if (underline) { + if (buffer.length > startLength) buffer ~= ", "; + buffer ~= "underlined"; + } + if (strikeout) { + if (buffer.length > startLength) buffer ~= ", "; + buffer ~= "striked out"; + } + if (rise != 0) { + if (buffer.length > startLength) buffer ~= ", "; + buffer ~= "rise="; + buffer ~= to!(char[])(rise); + } + if (metrics != null) { + if (buffer.length > startLength) buffer ~= ", "; + buffer ~= "metrics="; + buffer ~= metrics.toString; + } + buffer ~= "}"; + return buffer; +} + +} diff -r 4f9c0fea3440 -r b5521a2c27c2 todo.txt --- a/todo.txt Mon Jan 07 09:11:15 2008 +0100 +++ b/todo.txt Mon Jan 07 09:25:10 2008 +0100 @@ -52,7 +52,7 @@ graphics/Resource // OK graphics/RGB // OK graphics/TextLayout -graphics/TextStyle +graphics/TextStyle // OK graphics/Transform widgets/TableColumn