Mercurial > projects > dwt-linux
changeset 105:34e9dc2642d5
HelloWorld examples
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 18 Jan 2008 19:46:33 +0100 |
parents | 62a654ba5276 |
children | 396a9fa07672 |
files | .hgignore dsss.conf dwt/widgets/Label.d dwtexamples/helloworld.d dwtexamples/helloworld/HelloWorld1.d dwtexamples/helloworld/HelloWorld2.d dwtexamples/helloworld/HelloWorld3.d dwtexamples/helloworld/HelloWorld4.d dwtexamples/helloworld/HelloWorld5.d dwtexamples/simple.d |
diffstat | 10 files changed, 308 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Fri Jan 18 19:13:47 2008 +0100 +++ b/.hgignore Fri Jan 18 19:46:33 2008 +0100 @@ -8,4 +8,14 @@ ^dsss_objs ^dsss.last ^dsss_imports +^dwtexamples/simple$ +^dwtexamples/helloworld/HelloWorld1$ +^dwtexamples/helloworld/HelloWorld2$ +^dwtexamples/helloworld/HelloWorld3$ +^dwtexamples/helloworld/HelloWorld4$ +^dwtexamples/helloworld/HelloWorld5$ + + + +
--- a/dsss.conf Fri Jan 18 19:13:47 2008 +0100 +++ b/dsss.conf Fri Jan 18 19:46:33 2008 +0100 @@ -30,6 +30,10 @@ buildflags+=-I/home/frank/jive buildflags+=-g -gc -[dwtexamples/helloworld.d] +[dwtexamples/simple.d] [dwtexamples/helloworld/HelloWorld1.d] +[dwtexamples/helloworld/HelloWorld2.d] +[dwtexamples/helloworld/HelloWorld3.d] +[dwtexamples/helloworld/HelloWorld4.d] +[dwtexamples/helloworld/HelloWorld5.d] [t.d]
--- a/dwt/widgets/Label.d Fri Jan 18 19:13:47 2008 +0100 +++ b/dwt/widgets/Label.d Fri Jan 18 19:46:33 2008 +0100 @@ -424,6 +424,7 @@ if (imageHandle !is null) setBackgroundColor(imageHandle, color); } +alias Control.setBounds setBounds; int setBounds (int x, int y, int width, int height, bool move, bool resize) { /* * Bug in GTK. For some reason, when the label is
--- a/dwtexamples/helloworld.d Fri Jan 18 19:13:47 2008 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -module helloworld; - -import dwt.DWT; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Composite; -import dwt.widgets.Button; -import dwt.widgets.Text; - -import tango.io.Stdout; -import tango.math.Math; -import tango.text.convert.Format; -import tango.util.Convert; -import tango.util.PathUtil; -import dwt.events.SelectionListener; -import dwt.events.SelectionEvent; - - -import dwt.DWT; -import dwt.widgets.Display; - -import jive.stacktrace; - -void main(){ - - TraceConfig.throwOnAll = true; - try{ - - //Display.static_this(); - //PngChunk.static_this(); - //JPEGFileFormat.static_this(); - - Display display = new Display(); - Shell shell = new Shell(display); - shell.setSize(300, 200); - shell.setText("Simple DWT Sample"); - auto btn = new Button( shell, DWT.PUSH ); - btn.setBounds(40, 50, 100, 50); - btn.setText( "hey" ); - - auto txt = new Text(shell, DWT.BORDER); - txt.setBounds(170, 50, 100, 40); - - btn.addSelectionListener(new class () SelectionListener { - public void widgetSelected(SelectionEvent event) { - txt.setText("No problem"); - } - public void widgetDefaultSelected(SelectionEvent event) { - txt.setText("No worries!"); - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - catch (Exception e) { - Stdout.formatln (e.toString); - } -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtexamples/helloworld/HelloWorld1.d Fri Jan 18 19:46:33 2008 +0100 @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 dwtexamples.helloworld.HelloWorld1; + + +import dwt.widgets.Display; +import dwt.widgets.Shell; + +/* + * This example demonstrates the minimum amount of code required + * to open an DWT Shell and process the events. + */ +void main(){ + Display display = new Display (); + Shell shell = new Shell (display); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + +// for unknown reason, there are linker errors. These imports are the workaround +import tango.io.Stdout; +import tango.math.Math; +import tango.text.convert.Format; +import tango.util.Convert; +import tango.util.PathUtil; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtexamples/helloworld/HelloWorld2.d Fri Jan 18 19:46:33 2008 +0100 @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 dwtexamples.helloworld.HelloWorld2; + +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.widgets.Shell; + +/* + * This example builds on HelloWorld1 and demonstrates the minimum amount + * of code required to open an DWT Shell with a Label and process the events. + */ + +void main(){ + Display display = new Display (); + Shell shell = new Shell (display); + Label label = new Label (shell, DWT.CENTER); + label.setText ("Hello_world"); + label.setBounds (shell.getClientArea ()); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + +// for unknown reason, there are linker errors. These imports are the workaround +import tango.io.Stdout; +import tango.math.Math; +import tango.text.convert.Format; +import tango.util.Convert; +import tango.util.PathUtil;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtexamples/helloworld/HelloWorld3.d Fri Jan 18 19:46:33 2008 +0100 @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 dwtexamples.helloworld.HelloWorld3; + +import dwt.DWT; +import dwt.events.ControlAdapter; +import dwt.events.ControlEvent; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.widgets.Shell; + +/* + * This example builds on HelloWorld2 and demonstrates how to resize the + * Label when the Shell resizes using a Listener mechanism. + */ + +void main () { + Display display = new Display (); + final Shell shell = new Shell (display); + final Label label = new Label (shell, DWT.CENTER); + label.setText ("Hello_world"); + label.pack(); + shell.addControlListener(new class() ControlAdapter { + public void controlResized(ControlEvent e) { + label.setBounds (shell.getClientArea ()); + } + }); + shell.pack(); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + +// for unknown reason, there are linker errors. These imports are the workaround +import tango.io.Stdout; +import tango.math.Math; +import tango.text.convert.Format; +import tango.util.Convert; +import tango.util.PathUtil;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtexamples/helloworld/HelloWorld4.d Fri Jan 18 19:46:33 2008 +0100 @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 dwtexamples.helloworld.HelloWorld4; + +import dwt.DWT; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.widgets.Shell; + +/* + * This example builds on HelloWorld2 and demonstrates how to resize the + * Label when the Shell resizes using a Layout. + */ +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout(new FillLayout()); + Label label = new Label (shell, DWT.CENTER); + label.setText ("Hello_world"); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + + +// for unknown reason, there are linker errors. These imports are the workaround +import tango.io.Stdout; +import tango.math.Math; +import tango.text.convert.Format; +import tango.util.Convert; +import tango.util.PathUtil;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtexamples/helloworld/HelloWorld5.d Fri Jan 18 19:46:33 2008 +0100 @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 dwtexamples.helloworld.HelloWorld5; + + +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.events.PaintEvent; +import dwt.events.PaintListener; +import dwt.graphics.Color; +import dwt.graphics.GC; +import dwt.graphics.Rectangle; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +/* + * This example builds on HelloWorld1 and demonstrates how to draw directly + * on an DWT Control. + */ + +void main () { + Display display = new Display (); + final Color red = new Color(display, 0xFF, 0, 0); + final Shell shell = new Shell (display); + shell.addPaintListener(new class() PaintListener { + public void paintControl(PaintEvent event){ + GC gc = event.gc; + gc.setForeground(red); + Rectangle rect = shell.getClientArea(); + gc.drawRectangle(rect.x + 10, rect.y + 10, rect.width - 20, rect.height - 20); + gc.drawString("Hello_world", rect.x + 20, rect.y + 20); + } + }); + shell.addDisposeListener (new class() DisposeListener { + public void widgetDisposed (DisposeEvent e) { + red.dispose(); + } + }); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + +// for unknown reason, there are linker errors. These imports are the workaround +import tango.io.Stdout; +import tango.math.Math; +import tango.text.convert.Format; +import tango.util.Convert; +import tango.util.PathUtil;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtexamples/simple.d Fri Jan 18 19:46:33 2008 +0100 @@ -0,0 +1,63 @@ +module dwtexample.simple; + +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Button; +import dwt.widgets.Text; + +import tango.io.Stdout; +import tango.math.Math; +import tango.text.convert.Format; +import tango.util.Convert; +import tango.util.PathUtil; +import dwt.events.SelectionListener; +import dwt.events.SelectionEvent; + + +import dwt.DWT; +import dwt.widgets.Display; + +import jive.stacktrace; + +void main(){ + + TraceConfig.throwOnAll = true; + try{ + + //Display.static_this(); + //PngChunk.static_this(); + //JPEGFileFormat.static_this(); + + Display display = new Display(); + Shell shell = new Shell(display); + shell.setSize(300, 200); + shell.setText("Simple DWT Sample"); + auto btn = new Button( shell, DWT.PUSH ); + btn.setBounds(40, 50, 100, 50); + btn.setText( "hey" ); + + auto txt = new Text(shell, DWT.BORDER); + txt.setBounds(170, 50, 100, 40); + + btn.addSelectionListener(new class () SelectionListener { + public void widgetSelected(SelectionEvent event) { + txt.setText("No problem"); + } + public void widgetDefaultSelected(SelectionEvent event) { + txt.setText("No worries!"); + } + }); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + catch (Exception e) { + Stdout.formatln (e.toString); + } +} +