1 #!/usr/bin/env dub 2 /+ 3 dub.sdl: 4 name "snippet268" 5 dependency "dwt" path="../../../../../../" 6 libs \ 7 "atk-1.0" \ 8 "cairo" \ 9 "dl" \ 10 "fontconfig" \ 11 "gdk-x11-2.0" \ 12 "gdk_pixbuf-2.0" \ 13 "glib-2.0" \ 14 "gmodule-2.0" \ 15 "gnomeui-2" \ 16 "gnomevfs-2" \ 17 "gobject-2.0" \ 18 "gthread-2.0" \ 19 "gtk-x11-2.0" \ 20 "pango-1.0" \ 21 "pangocairo-1.0" \ 22 "X11" \ 23 "Xcomposite" \ 24 "Xcursor" \ 25 "Xdamage" \ 26 "Xext" \ 27 "Xfixes" \ 28 "Xi" \ 29 "Xinerama" \ 30 "Xrandr" \ 31 "Xrender" \ 32 "Xtst" \ 33 platform="linux" 34 +/ 35 36 /******************************************************************************* 37 * Copyright (c) 2000, 2004 IBM Corporation and others. 38 * All rights reserved. This program and the accompanying materials 39 * are made available under the terms of the Eclipse Public License v1.0 40 * which accompanies this distribution, and is available at 41 * http://www.eclipse.org/legal/epl-v10.html 42 * 43 * Contributors: 44 * IBM Corporation - initial API and implementation 45 * D Port: 46 * Thomas Demmer <t_demmer AT web DOT de> 47 *******************************************************************************/ 48 module org.eclipse.swt.snippets.Snippet268; 49 50 /* 51 * UI Automation (for testing tools) snippet: post mouse wheel events to a styled text 52 * 53 * For a list of all SWT example snippets see 54 * http://www.eclipse.org/swt/snippets/ 55 * 56 * @since 3.0 57 */ 58 import org.eclipse.swt.SWT; 59 import org.eclipse.swt.widgets.Display; 60 import org.eclipse.swt.widgets.Event; 61 import org.eclipse.swt.widgets.Listener; 62 import org.eclipse.swt.widgets.Shell; 63 64 import java.lang.all; 65 66 import org.eclipse.swt.custom.StyledText; 67 import org.eclipse.swt.graphics.Point; 68 import org.eclipse.swt.layout.FillLayout; 69 70 version(Tango){ 71 import tango.io.Stdout; 72 import tango.util.Convert; 73 } else { // Phobos 74 import std.stdio; 75 import std.conv; 76 } 77 78 void main(String[] args) { 79 Display display = new Display(); 80 Shell shell = new Shell(display); 81 shell.setLayout(new FillLayout()); 82 StyledText styledText = new StyledText(shell, SWT.V_SCROLL); 83 String multiLineString = ""; 84 for (int i = 0; i < 200; i++) { 85 multiLineString ~= "This is line number " ~ to!(String)(i) ~ 86 " in the multi-line string.\n"; 87 } 88 styledText.setText(multiLineString); 89 shell.setSize(styledText.computeSize(SWT.DEFAULT, 400)); 90 shell.open(); 91 styledText.addListener(SWT.MouseWheel, dgListener( (Event e){ 92 version(Tango){ 93 Stdout.formatln("Mouse Wheel event {}\n", e); 94 Stdout.flush(); 95 } else { 96 writefln("Mouse Wheel event %s", e); 97 } 98 })); 99 bool disposed = false; 100 Point pt = display.map(shell, null, 50, 50); 101 Thread thread = new Thread({ 102 Event event; 103 for (int i = 0; i < 50; i++) { 104 event = new Event(); 105 event.type = SWT.MouseWheel; 106 event.detail = SWT.SCROLL_LINE; 107 event.x = pt.x; 108 event.y = pt.y; 109 event.count = -2; 110 if (disposed) return; 111 display.syncExec(new class Runnable { 112 override void run() { 113 display.post(event); 114 } 115 }); 116 try { 117 Thread.sleep(400); 118 } catch (InterruptedException e) {} 119 } 120 version(Tango){ 121 Stdout("Thread done\n").flush(); 122 } else { 123 writeln("Thread done"); 124 } 125 }); 126 127 thread.start(); 128 while (!shell.isDisposed()) { 129 if (!display.readAndDispatch()) display.sleep(); 130 } 131 disposed = true; 132 thread.join(); 133 display.dispose(); 134 }