view org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/Bullet.d @ 120:536e43f63c81

Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661 ===D2=== * added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements used these templates to work with strict type storage rules of dmd-2.053 * com.ibm.icu now also compilable with D2, but not tested yet * small fixes Snippet288 - shared data is in TLS ===Phobos=== * fixed critical bugs in Phobos implemention completely incorrect segfault prone fromStringz (Linux's port ruthless killer) terrible, incorrect StringBuffer realization (StyledText killer) * fixed small bugs as well Snippet72 - misprint in the snippet * implemented missed functionality for Phobos ByteArrayOutputStream implemented (image loading available) formatting correctly works for all DWT's cases As a result, folowing snippets now works with Phobos (Snippet### - what is fixed): Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting Snippet48, 282 - crash on image loading Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText Snippet244 - hang-up ===Tango=== * few changes for the latest Tango trunc-r5661 * few small performance improvments ===General=== * implMissing-s for only one version changed to implMissingInTango/InPhobos * incorrect calls to Format in toString-s fixed * fixed loading \uXXXX characters in ResourceBundle * added good UTF-8 support for StyledText, TextLayout (Win32) and friends UTF functions revised and tested. It is now in java.nonstandard.*Utf modules StyledText and TextLayout (Win32) modules revised for UTF-8 support * removed small diferences in most identical files in *.swt.* folders *.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32 now 179 of 576 (~31%) files in *.swt.* folders are fully identical * Win32: snippets now have right subsystem, pretty icons and native system style controls * small fixes in snippets Snippet44 - it's not Snippet44 Snippet212 - functions work with different images and offsets arrays Win32: Snippet282 - crash on close if the button has an image Snippet293 - setGrayed is commented and others Win32: As a result, folowing snippets now works Snippet68 - color doesn't change Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above) Snippet193 - no tabel headers
author Denis Shelomovskij <verylonglogin.reg@gmail.com>
date Sat, 09 Jul 2011 15:50:20 +0300
parents 6dd524f61e62
children
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2000, 2008 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
 * Port to the D programming language:
 *     Frank Benoit <benoit@tionex.de>
 *******************************************************************************/
module org.eclipse.swt.custom.Bullet;

import java.lang.all;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.ST;

/**
 * Instances of this class represent bullets in the <code>StyledText</code>.
 * <p>
 * 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.
 * </p>
 * <p>
 * Application code does <em>not</em> need to explicitly release the
 * resources managed by each instance when those instances are no longer
 * required, and thus no <code>dispose()</code> method is provided.
 * </p>
 *
 * @see StyledText#setLineBullet(int, int, Bullet)
 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
 *
 * @since 3.2
 */
public class Bullet {
    /**
    * The bullet type.  Possible values are:
    * <ul>
    * <li><code>ST.BULLET_DOT</code></li>
    * <li><code>ST.BULLET_NUMBER</code></li>
    * <li><code>ST.BULLET_LETTER_LOWER</code></li>
    * <li><code>ST.BULLET_LETTER_UPPER</code></li>
    * <li><code>ST.BULLET_TEXT</code></li>
    * <li><code>ST.BULLET_CUSTOM</code></li>
    * </ul>
    */
    public int type;

    /**
    * The bullet style.
    */
    public StyleRange style;

    /**
    * The bullet text.
    */
    public String text;

    int[] linesIndices;
    int count;

/**
 * Create a new bullet with the specified style, and type <code>ST.BULLET_DOT</code>. 
 * The style must have a glyph metrics set.
 *
 * @param style the style
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li>
 * </ul>
 */
public this(StyleRange style) {
    this(ST.BULLET_DOT, style);
}
/**
 * Create a new bullet the specified style and type.
 * The style must have a glyph metrics set.
 *
 * @param type the bullet type
 * @param style the style
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li>
 * </ul>
 */
public this(int type, StyleRange style) {
    if (style is null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if (style.metrics is null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    this.type = type;
    this.style = style;
}
void addIndices (int startLine, int lineCount) {
    if (linesIndices is null) {
        linesIndices = new int[lineCount];
        count = lineCount;
        for (int i = 0; i < lineCount; i++) linesIndices[i] = startLine + i;
    } else {
        int modifyStart = 0;
        while (modifyStart < count) {
            if (startLine <= linesIndices[modifyStart]) break;
            modifyStart++;
        }
        int modifyEnd = modifyStart;
        while (modifyEnd < count) {
            if (startLine + lineCount <= linesIndices[modifyEnd]) break;
            modifyEnd++;
        }
        int newSize = modifyStart + lineCount + count - modifyEnd;
        if (newSize > linesIndices.length) {
            int[] newLinesIndices = new int[newSize];
            System.arraycopy(linesIndices, 0, newLinesIndices, 0, count);
            linesIndices = newLinesIndices;
        }
        System.arraycopy(linesIndices, modifyEnd, linesIndices, modifyStart + lineCount, count - modifyEnd);
        for (int i = 0; i < lineCount; i++) linesIndices[modifyStart + i] = startLine + i;
        count = newSize;
    }
}
int indexOf (int lineIndex) {
    for (int i = 0; i < count; i++) {
        if (linesIndices[i] is lineIndex) return i;
    }
    return -1;
}
public override hash_t toHash() {
    return style.toHash() ^ type;
}
int[] removeIndices (int startLine, int replaceLineCount, int newLineCount, bool update) {
    if (count is 0) return null;
    if (startLine > linesIndices[count - 1]) return null;
    int endLine = startLine + replaceLineCount;
    int delta = newLineCount - replaceLineCount;
    for (int i = 0; i < count; i++) {
        int index = linesIndices[i];
        if (startLine <= index) {
            int j = i;
            while (j < count) {
                if (linesIndices[j] >= endLine) break;
                j++;
            }
            if (update) {
                for (int k = j; k < count; k++) linesIndices[k] += delta;
            }
            int[] redrawLines = new int[count - j];
            System.arraycopy(linesIndices, j, redrawLines, 0, count - j);
            System.arraycopy(linesIndices, j, linesIndices, i, count - j);
            count -= (j - i);
            return redrawLines;
        }
    }
    for (int i = 0; i < count; i++) linesIndices[i] += delta;
    return null;
}
int size() {
    return count;
}
}