# HG changeset patch # User Frank Benoit # Date 1205013384 -3600 # Node ID 11cb40a34da10dfbae6722c544c4b819a20353a3 # Parent 7c3196948c7f16c1c7125f13ba276cff45f18bd8 SleakExample diff -r 7c3196948c7f -r 11cb40a34da1 dsss.conf --- a/dsss.conf Fri Mar 07 02:46:18 2008 +0100 +++ b/dsss.conf Sat Mar 08 22:56:24 2008 +0100 @@ -1,6 +1,6 @@ [*] -debugflags+=-g -gc -debug +buildflags+=-g -gc #used for dwtsnippets/text/Snippet258 #dwtsnippets/expandbar/Snippet223 @@ -52,8 +52,12 @@ [user/drawingboard/DrawingBoard.d] [user/torhu_synctest.d] +version(DwtAddons){ + [dwtexamples/sleak/SleakExample.d] +} + version(Derelict){ -[dwtsnippets/opengl/Snippet195.d] + [dwtsnippets/opengl/Snippet195.d] } [dwtexamples/addressbook/AddressBook.d] diff -r 7c3196948c7f -r 11cb40a34da1 dwtexamples/sleak/SleakExample.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtexamples/sleak/SleakExample.d Sat Mar 08 22:56:24 2008 +0100 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. + * This file is made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Port to the D programming language + * Frank Benoit + */ +module dwtexamples.sleak.SleakExample; + +import dwt.program.Program; +import dwt.graphics.ImageData; +import dwt.graphics.Image; +import dwt.layout.FillLayout; +import dwt.events.PaintListener; +import dwt.events.PaintEvent; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import tango.io.Stdout; +version(JIVE){ + import jive.stacktrace; +} + +void main() { + Display display; + Shell shell; + List list; + Canvas canvas; + Image image; + + version( all ){ + DeviceData data = new DeviceData(); + data.tracking = true; + display = new Display(data); + Sleak sleak = new Sleak(); + sleak.open(); + } + else{ + display = new Display(); + } + + shell = new Shell(display); + shell.setLayout(new FillLayout()); + list = new List(shell, DWT.BORDER | DWT.SINGLE | DWT.V_SCROLL | DWT.H_SCROLL); + list.setItems(Program.getExtensions()); + canvas = new Canvas(shell, DWT.BORDER); + canvas.addPaintListener(new class() PaintListener { + public void paintControl(PaintEvent e) { + if (image !is null) { + e.gc.drawImage(image, 0, 0); + } + } + }); + list.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + image = null; // potentially leak one image + char[][] selection = list.getSelection(); + if (selection.length !is 0) { + Program program = Program.findProgram(selection[0]); + if (program !is null) { + ImageData imageData = program.getImageData(); + if (imageData !is null) { + if (image !is null) image.dispose(); + image = new Image(display, imageData); + } + } + } + canvas.redraw(); + } + }); + shell.setSize(shell.computeSize(DWT.DEFAULT, 200)); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } +}