Mercurial > projects > dwt2
view org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/custom/AnimatedProgress.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 | fb3aa8075988 |
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.AnimatedProgress; import org.eclipse.swt.SWT; import org.eclipse.swt.SWTException; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import java.lang.Runnable; /** * A control for showing progress feedback for a long running operation. * * @deprecated As of Eclipse 2.1, use ProgressBar with the style SWT.INDETERMINATE * * <dl> * <dt><b>Styles:</b><dd>VERTICAL, HORIZONTAL, BORDER * </dl> * * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class AnimatedProgress : Canvas { alias Canvas.computeSize computeSize; static const int SLEEP = 70; static const int DEFAULT_WIDTH = 160; static const int DEFAULT_HEIGHT = 18; bool active = false; bool showStripes = false; int value; int orientation = SWT.HORIZONTAL; bool showBorder = false; /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. * <p> * The style value is either one of the style constants defined in * class <code>SWT</code> which is applicable to instances of this * class, or must be built by <em>bitwise OR</em>'ing together * (that is, using the <code>int</code> "|" operator) two or more * of those <code>SWT</code> style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. * </p> * * @param parent a widget which will be the parent of the new instance (cannot be null) * @param style the style of widget to construct * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> * </ul> * * @see SWT#VERTICAL * @see SWT#HORIZONTAL * @see SWT#BORDER * @see #getStyle() */ public this(Composite parent, int style) { super(parent, checkStyle(style)); if ((style & SWT.VERTICAL) !is 0) { orientation = SWT.VERTICAL; } showBorder = (style & SWT.BORDER) !is 0; addControlListener(new class() ControlAdapter { public void controlResized(ControlEvent e) { redraw(); } }); addPaintListener(new class() PaintListener { public void paintControl(PaintEvent e) { paint(e); } }); addDisposeListener(new class() DisposeListener { public void widgetDisposed(DisposeEvent e){ stop(); } }); } private static int checkStyle (int style) { int mask = SWT.NONE; return style & mask; } /** * Stop the animation if it is not already stopped and * reset the presentation to a blank appearance. * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public void clear(){ synchronized { checkWidget(); if (active) stop(); showStripes = false; redraw(); } } public override Point computeSize(int wHint, int hHint, bool changed) { checkWidget(); Point size = null; if (orientation is SWT.HORIZONTAL) { size = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT); } else { size = new Point(DEFAULT_HEIGHT, DEFAULT_WIDTH); } if (wHint !is SWT.DEFAULT) size.x = wHint; if (hHint !is SWT.DEFAULT) size.y = hHint; return size; } private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) { gc.setForeground(topleft); gc.drawLine(x, y, x+w-1, y); gc.drawLine(x, y, x, y+h-1); gc.setForeground(bottomright); gc.drawLine(x+w, y, x+w, y+h); gc.drawLine(x, y+h, x+w, y+h); } void paint(PaintEvent event) { GC gc = event.gc; Display disp= getDisplay(); Rectangle rect= getClientArea(); gc.fillRectangle(rect); if (showBorder) { drawBevelRect(gc, rect.x, rect.y, rect.width-1, rect.height-1, disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); } paintStripes(gc); } void paintStripes(GC gc) { if (!showStripes) return; Rectangle rect= getClientArea(); // Subtracted border painted by paint. rect = new Rectangle(rect.x+2, rect.y+2, rect.width-4, rect.height-4); gc.setLineWidth(2); gc.setClipping(rect); Color color = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION); gc.setBackground(color); gc.fillRectangle(rect); gc.setForeground(this.getBackground()); int step = 12; int foregroundValue = value is 0 ? step - 2 : value - 2; if (orientation is SWT.HORIZONTAL) { int y = rect.y - 1; int w = rect.width; int h = rect.height + 2; for (int i= 0; i < w; i+= step) { int x = i + foregroundValue; gc.drawLine(x, y, x, h); } } else { int x = rect.x - 1; int w = rect.width + 2; int h = rect.height; for (int i= 0; i < h; i+= step) { int y = i + foregroundValue; gc.drawLine(x, y, w, y); } } if (active) { value = (value + 2) % step; } } /** * Start the animation. * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public void start() { synchronized { checkWidget(); if (active) return; active = true; showStripes = true; Display display = getDisplay(); Runnable [] timer = new Runnable [1]; timer [0] = new class( display, timer ) Runnable { Display disp; Runnable [] runs; this( Display disp, Runnable[] runs ){ this.disp = disp; this.runs = runs; } public void run () { if (!active) return; GC gc = new GC(this.outer); paintStripes(gc); gc.dispose(); disp.timerExec (SLEEP, runs [0]); } }; display.timerExec (SLEEP, timer [0]); } } /** * Stop the animation. Freeze the presentation at its current appearance. */ public void stop() { synchronized { //checkWidget(); active = false; } } }