diff options
Diffstat (limited to 'tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse')
42 files changed, 4012 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug160691_SWTAWTShell.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug160691_SWTAWTShell.java new file mode 100644 index 0000000000..1dc4223169 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug160691_SWTAWTShell.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 160691 - RFE: Please add a snipplet about SWT_AWT.new_Shell + * How to run: snippet shows lack of features + * Bug description: N/A, enhancement and not a bug + * Expected results: N/A, enhancement and not a bug + * GTK Version(s): N/A + */ +public class Bug160691_SWTAWTShell { + + public static void main(String[] args) { + java.awt.Frame frame = new java.awt.Frame("AWT Frame"); + java.awt.Button button = new java.awt.Button("AWT Button"); + frame.add(button, java.awt.BorderLayout.NORTH); + java.awt.Canvas canvas = new java.awt.Canvas(); + frame.add(canvas, java.awt.BorderLayout.CENTER); + + frame.addNotify(); + + Display display = new Display(); + Shell shell = SWT_AWT.new_Shell(display, canvas); + shell.setLayout(new FillLayout()); + Button swtButton = new Button(shell, SWT.PUSH); + swtButton.setText("SWT Button"); + + frame.setBounds(20, 20, 300, 300); + shell.layout(); + frame.setVisible(true); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } +} +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug164015_G2DDrawImage.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug164015_G2DDrawImage.java new file mode 100644 index 0000000000..fc3459b131 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug164015_G2DDrawImage.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JPanel; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 164015 - AWT_SWT bridge hangs on g2D.drawImage(bufferedImage) and then segfaults + * How to run: launch snippet, JVM should segfault + * Bug description: JVM segfault + * Expected results: The image is drawn correctly in the window + * GTK Version(s): N/A + */ +public class Bug164015_G2DDrawImage extends JPanel { + + private static final long serialVersionUID = -6507131039136726834L; + + private static final int TILE_SIZE = 200; + + private static final boolean USE_JAI_FOR_IMAGE_IO = true; + + private int viewport_x = 0, viewport_y = 0; + + /** constructor */ + public Bug164015_G2DDrawImage() { + this.setDoubleBuffered(false); // this makes the bug show up faster + + } + + /** scroll the viewport */ + public void scroll(int x, int y) { + viewport_x += x; + viewport_y += y; + this.repaint(); + } + + public BufferedImage loadTile(int x, int y) { + String file_path = "tile_" + x + "_" + y + ".gif"; + BufferedImage bufferedImage = null; + + if (USE_JAI_FOR_IMAGE_IO) { + + try { + bufferedImage = ImageIO.read(new File(file_path)); + } catch (IOException e) { + bufferedImage = null; + } + + } else { // use AWT + Image image = new ImageIcon(file_path).getImage(); + if (image.getWidth(null) <= 0 || image.getHeight(null) <= 0) { + return null; + } + bufferedImage = new BufferedImage(image.getWidth(null), image + .getHeight(null), BufferedImage.TYPE_INT_ARGB); + bufferedImage.getGraphics().drawImage(image, 0, 0, null); + } + + return bufferedImage; + } + + @Override + public void paint(Graphics g) { + + super.paint(g); + + Graphics2D g2D = (Graphics2D) g; + + int firsttile_x = viewport_x - viewport_x % TILE_SIZE; + int firsttile_y = viewport_y - viewport_y % TILE_SIZE; + int lasttile_x = firsttile_x + + (this.getWidth() / TILE_SIZE + 2) * TILE_SIZE; + int lasttile_y = firsttile_y + + (this.getHeight() / TILE_SIZE + 2) * TILE_SIZE; + + for (int currtile_y = firsttile_y; currtile_y < lasttile_y; currtile_y += TILE_SIZE) { + for (int currtile_x = firsttile_x; currtile_x < lasttile_x; currtile_x += TILE_SIZE) { + + BufferedImage currentImage = loadTile(currtile_x, currtile_y); + if (currentImage != null) { + System.err.print("drawing graphics.image... "); + g2D.drawImage(currentImage, currtile_x - viewport_x, + currtile_y - viewport_y, null); + System.err.println("done"); + } + + g2D.setColor(Color.RED); // outline the tiles + g2D.drawRect(currtile_x - viewport_x, currtile_y - viewport_y, + TILE_SIZE, TILE_SIZE); + + } + } + + } + + public static void main(String[] args) { + /** create SWT GUI */ + Display display = new Display(); + Shell shell = new Shell(display); + shell.setText("AWT_SWT Test"); + + Composite swtAwtComponent = new Composite(shell, SWT.EMBEDDED); + java.awt.Frame frame = SWT_AWT.new_Frame(swtAwtComponent); + final Bug164015_G2DDrawImage myJPanel = new Bug164015_G2DDrawImage(); + frame.add(myJPanel); + + frame.addKeyListener(new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + + if (e.getKeyCode() == KeyEvent.VK_LEFT) { + myJPanel.scroll(20, 0); + } + if (e.getKeyCode() == KeyEvent.VK_RIGHT) { + myJPanel.scroll(-20, 0); + } + if (e.getKeyCode() == KeyEvent.VK_UP) { + myJPanel.scroll(0, 20); + } + if (e.getKeyCode() == KeyEvent.VK_DOWN) { + myJPanel.scroll(0, -20); + } + } + + }); + + shell.setLayout(new FillLayout()); + shell.pack(); + shell.open(); + shell.setMaximized(true); + + try { + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + + } finally { + display.dispose(); + System.err.println("EXITING NORMALLY!!"); + } + } + +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug166720_TableEditorFlicker.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug166720_TableEditorFlicker.java new file mode 100644 index 0000000000..2b5eb1da57 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug166720_TableEditorFlicker.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.TableEditor; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; + +/* + * Title: Bug 166720 - [TableEditor] flickers quite a bit when scrolling - Linux GTK + * How to run: launch snippet and scroll TableEditor. + * Bug description: TableEditor flickers when scrolling. + * Expected results: TableEditor should scroll smoothly. + * GTK Version(s): GTK2.x + */ +public class Bug166720_TableEditorFlicker { + public static void main(String[] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout (new GridLayout ()); + Table table = new Table (shell, SWT.BORDER | SWT.MULTI); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = 200; + gd.widthHint = 200; + table.setLayoutData(gd); + + TableColumn column = new TableColumn(table, SWT.NONE); + column.setWidth (100); + for (int i=0; i<100; i++) { + new TableItem (table, SWT.NONE); + } + TableItem [] items = table.getItems (); + for (int i=0; i<items.length; i++) { + TableEditor editor = new TableEditor (table); + editor = new TableEditor (table); + Text text = new Text (table, SWT.NONE); + text.setText("Text" + i); + editor.grabHorizontal = true; + editor.setEditor(text, items[i], 0); + editor = new TableEditor (table); + } + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug170631_NestedCompositeFocus.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug170631_NestedCompositeFocus.java new file mode 100644 index 0000000000..1fef9f735b --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug170631_NestedCompositeFocus.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/* + * Title: Bug 170631 - [Widgets] First nested composite takes focus unexpectedly + * How to run: launch snippet and hit tab + * Bug description: Text does not get focus + * Expected results: Text should get focus and keep it. + * GTK Version(s): GTK2.x + */ +public class Bug170631_NestedCompositeFocus { + +public static void main(String [] args) { + final Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new GridLayout()); + final Canvas canvas = new Canvas(shell, SWT.NONE); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + canvas.setLayoutData(gridData); + canvas.addPaintListener(event -> { + Rectangle rect = canvas.getClientArea(); + event.gc.drawOval(0, 0, rect.width - 1, rect.height - 1); + }); + + final Text text = new Text(shell, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + text.setText("I want focus"); + + shell.setBounds(10, 10, 200, 200); + + shell.open (); + + // With shell.setFocus(), the Canvas gets focus. Without it, the Text does. + shell.setFocus(); + + System.out.println(shell.getDisplay().getFocusControl()); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); +} +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug186038_DNDActivateEvent.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug186038_DNDActivateEvent.java new file mode 100644 index 0000000000..231f6d2a07 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug186038_DNDActivateEvent.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.DropTargetListener; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + + +/* + * Title: Bug 186038 - [DND] On Linux-gtk, the SWT.Activate event is not fired to the popup shell during a dragging operation + * How to run: launch snippet, drag source button to target. + * Bug description: When the shell appears, clicking outside of it does not dismiss it + * Expected results: The shell should be dismissed. + * GTK Version(s): GTK2.x + */ +public class Bug186038_DNDActivateEvent { + + public static void main(String[] args) { + + Display display = new Display(); + final Shell shell = new Shell(display); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + shell.setLayout(layout); + + // create the drop down widget.shell + final Shell dropDownShell = new Shell(shell, SWT.ON_TOP | SWT.DROP_DOWN); + dropDownShell.setLayout(new RowLayout()); + dropDownShell.setVisible(false); + + dropDownShell.addListener(SWT.Activate, event -> System.out.println("dropDownShell gets Activate event!")); + + dropDownShell.addListener(SWT.Deactivate, event -> { + System.out.println( + "dropDownShell entering Deactivate event handler and will hide the dropdown widget.shell"); + hideDropDown(dropDownShell); + }); + + dropDownShell.addListener(SWT.Close, event -> hideDropDown(dropDownShell)); + + // create the button1 and when it is hovered, display the dropdown + final Button button1 = new Button(shell, SWT.PUSH); + button1.setText("Drop target"); + button1.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (!dropDownShell.isVisible()) { + showDropDown(button1, dropDownShell); + } + } + }); + + int operations = DND.DROP_COPY | DND.DROP_DEFAULT; + DropTarget target = new DropTarget(button1, operations); + // Provide data in Text format + Transfer[] types = new Transfer[] { TextTransfer.getInstance() }; + target.setTransfer(types); + + target.addDropListener(new DropTargetListener() { + @Override + public void dragEnter(DropTargetEvent event) { + if (event.detail == DND.DROP_DEFAULT) { + if ((event.operations & DND.DROP_COPY) != 0) { + event.detail = DND.DROP_COPY; + } else { + event.detail = DND.DROP_NONE; + } + } + for (int i = 0; i < event.dataTypes.length; i++) { + if (TextTransfer.getInstance().isSupportedType(event.dataTypes[i])) { + event.currentDataType = event.dataTypes[i]; + if (event.detail != DND.DROP_COPY) { + event.detail = DND.DROP_NONE; + } + break; + } + } + } + + @Override + public void dragOver(DropTargetEvent event) { + event.feedback = DND.FEEDBACK_SELECT; + + if (!dropDownShell.isVisible()) { + showDropDown(button1, dropDownShell); + } + } + + @Override + public void dragOperationChanged(DropTargetEvent event) { + + } + + @Override + public void dragLeave(DropTargetEvent event) { + } + + @Override + public void dropAccept(DropTargetEvent event) { + } + + @Override + public void drop(DropTargetEvent event) { + if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) { + String text = (String) event.data; + System.out.println(text); + } + } + }); + + // create the button2 as the drag source + final Button button2 = new Button(shell, SWT.PUSH); + button2.setText("Drag source"); + + operations = DND.DROP_COPY; + DragSource source = new DragSource(button2, operations); + + // Provide data in Text format + source.setTransfer(types); + + source.addDragListener(new DragSourceListener() { + @Override + public void dragStart(DragSourceEvent event) { + if (button2.getText().length() == 0) { + event.doit = false; + } + } + + @Override + public void dragSetData(DragSourceEvent event) { + // Provide the data of the requested type. + if (TextTransfer.getInstance().isSupportedType(event.dataType)) { + event.data = button2.getText(); + } + } + + @Override + public void dragFinished(DragSourceEvent event) { + + } + }); + + shell.setSize(300, 300); + shell.addDisposeListener(e -> { + if (dropDownShell != null && !dropDownShell.isDisposed()) { + dropDownShell.dispose(); + } + }); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + + private static void showDropDown(final Button button1, final Shell dropDownShell) { + if (dropDownShell != null && !dropDownShell.isDisposed()) { + dropDownShell.setText("This is a drop down widget.shell"); + dropDownShell.setSize(100, 200); + Rectangle buttonRect = button1.getBounds(); + Point p = button1.getParent().toDisplay(new Point(buttonRect.x, buttonRect.y + buttonRect.height)); + dropDownShell.setLocation(p.x, p.y); + dropDownShell.setVisible(true); + dropDownShell.setFocus(); + } + } + + private static void hideDropDown(final Shell dropDownShell) { + dropDownShell.setVisible(false); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug221240_AWTJVMCrash.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug221240_AWTJVMCrash.java new file mode 100644 index 0000000000..dfa1d40876 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug221240_AWTJVMCrash.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Container; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.DeviceData; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 221240 - SWT_AWT bridge crashes JVM on Linux (X error BadWindow) + * How to run: launch snippet + * Bug description: The JVM crashes + * Expected results: The JVM should not crash + * GTK Version(s): N/A + */ +public class Bug221240_AWTJVMCrash extends JFrame { + + private static final long serialVersionUID = -248424300520098295L; + +protected static final String LS = System.getProperty("line.separator"); + + public Bug221240_AWTJVMCrash() { + setDefaultCloseOperation(EXIT_ON_CLOSE); + Canvas canvas = new Canvas() { + + private static final long serialVersionUID = -4380477744500979114L; + + @Override + public void addNotify() { + super.addNotify(); + final Canvas canvas_ = this; + display.asyncExec(() -> { + final Shell shell = SWT_AWT.new_Shell(display, canvas_); + shell.setLayout(new FillLayout()); + Browser browser = new Browser(shell, SWT.NONE); + browser.setText( + "<html>" + LS + + " <head>" + LS + + " <script language=\"JavaScript\" type=\"widget.text/javascript\">" + LS + + " <!--" + LS + + " function getEmbeddedObject() {" + LS + + " var movieName = \"myEmbeddedObject\";" + LS + + " if(window.document[movieName]) {" + LS + + " return window.document[movieName];" + LS + + " }" + LS + + " if(navigator.appName.indexOf(\"Microsoft Internet\") == -1) {" + LS + + " if(document.embeds && document.embeds[movieName]) {" + LS + + " return document.embeds[movieName];" + LS + + " }" + LS + + " } else {" + LS + + " return document.getElementById(movieName);" + LS + + " }" + LS + + " }" + LS + + " //-->" + LS + + " </script>" + LS + + " <style type=\"widget.text/css\">" + LS + + " html, object, embed, div, body, widget.table { width: 100%; height: 100%; min-height: 100%; margin: 0; padding: 0; overflow: hidden; background-graphics.color: #FFFFFF; widget.text-align: center; }" + LS + + " object, embed, div { position: absolute; left:0; top:0;}" + LS + + " td { vertical-align: middle; }" + LS + + " </style>" + LS + + " </head>" + LS + + " <body height=\"*\">" + LS + + " <script language=\"JavaScript\" type=\"widget.text/javascript\">" + LS + + " <!--" + LS + + getVLCPlayer() + + " var embeddedObject = getEmbeddedObject();" + LS + + " embeddedObject.style.width = '100%';" + LS + + " embeddedObject.style.height = '100%';" + LS + + " //-->" + LS + + " </script>" + LS + + " </body>" + LS + + "</html>" + LS); + // The initial size is wrong so we have to force it + shell.setSize(canvas_.getWidth(), canvas_.getHeight()); + }); + } + }; + Container contentPane = getContentPane(); + JButton swingButton = new JButton("Open a file chooser!"); + swingButton.addActionListener(e -> new JFileChooser().showOpenDialog(Bug221240_AWTJVMCrash.this)); + contentPane.add(swingButton, BorderLayout.NORTH); + contentPane.add(canvas, BorderLayout.CENTER); + setSize(800, 600); + } + + private String getVLCPlayer() { +// String escapedURL = "http://80.118.196.219/webtv-asx.cgi?channel=nrj_hits"; +// String escapedURL = "http://media.xored.com/eclipsecon2007/dltk-javascript-jdt.mov"; + String escapedURL = url != null ? url: "http://flv.thruhere.net/presentations/java-comes-home-customer-haase.flv"; + return + "window.document.write('<object classid=\"clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8\" id=\"myEmbeddedObject\" codebase=\"http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab\" events=\"true\">');" + LS + + "window.document.write(' <param name=\"Src\" value=\"' + decodeURIComponent('" + escapedURL + "') + '\";\"/>');" + LS + + "window.document.write(' <embed name=\"myEmbeddedObject\" target=\"" + escapedURL + "\" type=\"application/x-vlc-plugin\" pluginspage=\"http://www.videolan.org\">');" + LS + + "window.document.write(' </embed>');" + LS + + "window.document.write('</object>');" + LS; + } + +// private String getFlashPlayer() { +// String escapedURL = "http://www.freedominteractivedesign.com/swf/main.swf"; +// return +// "window.document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" id=\"myEmbeddedObject\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" events=\"true\">');" + LS + +// "window.document.write(' <param name=\"movie\" value=\"' + decodeURIComponent('" + escapedURL + "') + '\";\"/>');" + LS + +// "window.document.write(' <embed name=\"myEmbeddedObject\" src=\"" + escapedURL + "\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\">');" + LS + +// "window.document.write(' </embed>');" + LS + +// "window.document.write('</object>');" + LS; +// } + + private static Display display; + + private static String url; + + public static void main(String[] args) { + DeviceData data = new DeviceData(); + data.debug = true; + display = new Display(data); + Device.DEBUG = true; + if(args.length > 0) { + url = args[0]; + } + System.setProperty("sun.awt.xembedserver", "true"); + SwingUtilities.invokeLater(() -> new Bug221240_AWTJVMCrash().setVisible(true)); + while(true) { + if(!display.readAndDispatch()) { + display.sleep(); + } + } + } + +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug221611_RadioButtonAccessibility.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug221611_RadioButtonAccessibility.java new file mode 100644 index 0000000000..028401885a --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug221611_RadioButtonAccessibility.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 221611 - [Accessibility] Radio button being read as check boxes + * How to run: launch snippet + * Bug description: Checking button 2, button 3, will cause Orca to read button 3 + * as a checkbox button + * Expected results: All buttons should be read as radio buttons + * GTK Version(s): GTK2 + */ + +public class Bug221611_RadioButtonAccessibility { + + public static void main(String[] args) { + Display display = Display.getDefault(); + Shell shell = new Shell(); + shell.setLayout(new GridLayout()); + + Composite parent = new Composite(shell, SWT.NONE); + parent.setLayout(new GridLayout()); + + Button button1 = new Button(parent, SWT.RADIO); + button1.setText("Button 1"); + Button button2 = new Button(parent, SWT.RADIO); + button2.setText("Button 2"); + button2.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + ((Button) e.widget).getAccessible(); + } + }); + Button button3 = new Button(parent, SWT.RADIO); + button3.setText("Button 3"); + Button button4 = new Button(parent, SWT.RADIO); + button4.setText("Button 4"); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) + if (!display.readAndDispatch()) + display.sleep(); + display.dispose(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug262974_ModalBrowserDialog.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug262974_ModalBrowserDialog.java new file mode 100644 index 0000000000..67598c9c59 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug262974_ModalBrowserDialog.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Container; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.LocationListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 262974 - [SWT_AWT] On Linux, Browser dialogs are not modal + * How to run: launch snippet and observe that the popup window is not modal + * Bug description: The popup is not modal + * Expected results: The popup should act as a modal dialog + * GTK Version(s): N/A + */ +public class Bug262974_ModalBrowserDialog extends JFrame { + + private static final long serialVersionUID = -4662730703780970912L; + + +public Bug262974_ModalBrowserDialog() { + setDefaultCloseOperation(EXIT_ON_CLOSE); + Canvas canvas = new Canvas() { + + private static final long serialVersionUID = -8128631529339936684L; + + @Override + public void addNotify() { + super.addNotify(); + final Canvas canvas_ = this; + display.asyncExec(() -> { + final Shell shell = SWT_AWT.new_Shell(display, canvas_); + shell.setLayout(new FillLayout()); + final Browser browser = new Browser(shell, SWT.NONE); + browser.setUrl("http://www.google.com"); + browser.addLocationListener(LocationListener.changedAdapter(e -> + display.asyncExec(() -> browser.execute("alert('some dialog');"))) + ); + // The initial size is wrong on Windows so we have to force it + shell.setSize(canvas_.getWidth(), canvas_.getHeight()); + }); + } + }; + Container contentPane = getContentPane(); + contentPane.add(canvas, BorderLayout.CENTER); + contentPane.add(new JButton("Some Swing Button"), BorderLayout.SOUTH); + setSize(400, 300); + } + + private static Display display; + + public static void main(String[] args) { + System.setProperty("sun.awt.noerasebackground", "true"); + System.setProperty("sun.awt.xembedserver", "true"); + display = new Display(); + SwingUtilities.invokeLater(() -> new Bug262974_ModalBrowserDialog().setVisible(true)); + while(true) { + if(!display.readAndDispatch()) { + display.sleep(); + } + } + } + +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug287038_TableKeyEvent.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug287038_TableKeyEvent.java new file mode 100644 index 0000000000..ca99307a32 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug287038_TableKeyEvent.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +/* + * Title: Bug 287083 - [Widgets] KeyListener on Table doesn't receive KeyEvents + * How to run: launch snippet and type into the Table + * Bug description: KeyEvents are only fired for first key pressed and ESC key. + * Expected results: KeyEvents should fire properly for all keys pressed. + * GTK Version(s): GTK2.x, GTK3.x + */ +public class Bug287038_TableKeyEvent { + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + final Table table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); + table.setLinesVisible(true); + for (int i = 0; i < 2; i++) { + TableColumn column = new TableColumn(table, SWT.NONE); + column.setWidth(100); + } + String[] itemsToAdd = new String[] { + "Cheese", "Potatoes", "Rocks", "Bacon", "Tree", "Forest", "Chocolate", "Broccoli", "Turnip", + "Squash", "Carrot" + }; + int i = 0; + for (String s : itemsToAdd) { + TableItem item = new TableItem(table, SWT.NONE); + item.setText(new String[] { + s, "" + i++ + }); + } + table.addKeyListener(new KeyListener() { + @Override + public void keyPressed(KeyEvent e) { + System.out.println(e.character); + } + + @Override + public void keyReleased(KeyEvent e) { + System.out.println(e.character); + } + }); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug290650_FillLayoutComputeSize.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug290650_FillLayoutComputeSize.java new file mode 100644 index 0000000000..a1cc03e8be --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug290650_FillLayoutComputeSize.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/* + * Title: Bug 290650 - [Layout] If a composite with a FillLayout (with marginWidth != 0) + * contains a widget which could expand depending on a fixed width or height, than computeSize() + * doesn't calculate the expanding size correctly. + * How to run: launch snippet and observe size of Text widgets + * Bug description: One widget is only one line in height when it should be two + * Expected results: Both widgets should be 2 lines in height + * GTK Version(s): GTK2.x, GTK3.x + */ +public class Bug290650_FillLayoutComputeSize { + private static int margin = 100; + private static String msg = "This is a message with 2 lines and some text"; + + private static void init(Shell shell) { + Composite container1 = new Composite(shell, SWT.NONE); + FillLayout fillLayout1 = new FillLayout(); + fillLayout1.marginWidth = margin; + container1.setLayout(fillLayout1); + container1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); + + Text text1 = new Text(container1, SWT.WRAP); + text1.setText(msg); + + Point containerSize1 = container1.computeSize(shell.getClientArea().width, SWT.DEFAULT); + container1.setSize(containerSize1); + + Composite container2 = new Composite(shell, SWT.NONE); + container2.setLocation(margin, 50); + FillLayout fillLayout2 = new FillLayout(); + container2.setLayout(fillLayout2); + container2.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); + + Text text2 = new Text(container2, SWT.WRAP); + text2.setText(msg); + + Point containerSize2 = container2.computeSize(shell.getClientArea().width-2*margin, SWT.DEFAULT); + container2.setSize(containerSize2); + + } + + public static void main(String[] args) { + final Display display = new Display(); + Shell shell = new Shell(display); + shell.setText("Fill Layout with Text-Widget Test"); + shell.setSize(190 + 2 * margin, 400); + init(shell); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug306067_DesktopEffectShellEvent.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug306067_DesktopEffectShellEvent.java new file mode 100644 index 0000000000..6ed0620bf9 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug306067_DesktopEffectShellEvent.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + + +/* + * Title: Bug 306067 - [Widgets] SWT.Deactivate event is not fired to the dropdown shell when enable the Desktop effect + * How to run: launch snippet and press button + * Bug description: Shell does not receive deactivate event + * Expected results: shell should receive deactivate event + * GTK Version(s): GTK2.x + */ +public class Bug306067_DesktopEffectShellEvent { + static Display display = null; + static Shell shell = null; + static Button button = null; + static Shell dropDownShell = null; + + public static void main(String[] args) { + Device.DEBUG = true; + display = new Display(); + shell = new Shell(display); + shell.setLayout(new RowLayout()); + + // create the drop down shell + dropDownShell = new Shell(shell, SWT.ON_TOP | SWT.DROP_DOWN); + dropDownShell.setLayout(new RowLayout()); + dropDownShell.setVisible(false); + dropDownShell.addListener(SWT.Deactivate, event -> { + System.out.println("dropDownShell entering Deactivate event handler and will hide the dropdown shell"); + hideDropDown(); + }); + + dropDownShell.addListener(SWT.Close, event -> hideDropDown()); + + + // create the button + button = new Button(shell, SWT.PUSH); + button.setText("Open"); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (!dropDownShell.isVisible()) { + System.out.println("Open button entering widgetSelected event handler and will show the dropdown shell"); + showDropDown(); + } + } + }); + + button.addMouseListener(new MouseAdapter() { + + @Override + public void mouseDown(MouseEvent e) { + System.out.println("Open button entering mouseDown event handler"); + super.mouseDown(e); + } + + @Override + public void mouseUp(MouseEvent e) { + System.out.println("Open button entering mouseUp event handler"); + super.mouseUp(e); + } + }); + + + shell.setSize(300, 300); + shell.addDisposeListener(e -> { + if (dropDownShell != null && !dropDownShell.isDisposed()) { + dropDownShell.dispose(); + dropDownShell = null; + } + }); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + + private static void showDropDown() { + if (dropDownShell != null && !dropDownShell.isDisposed()) { + dropDownShell.setText("This is a drop down shell"); + dropDownShell.setSize(100, 200); + Rectangle buttonRect = button.getBounds(); + Point p = button.getParent().toDisplay(new Point(buttonRect.x, buttonRect.y + buttonRect.height)); + dropDownShell.setLocation(p.x, p.y); + dropDownShell.setVisible(true); + dropDownShell.setFocus(); + } + } + + private static void hideDropDown() { + dropDownShell.setVisible(false); + } + +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug306490_SwingDisposeError.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug306490_SwingDisposeError.java new file mode 100644 index 0000000000..eabeba98ab --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug306490_SwingDisposeError.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.JFrame; +import javax.swing.JTextArea; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 306490 - [SWT/AWT] SWT and Swing in parallel crashes outside JVM with 'BadWindow' on Swing's dispose() + * How to run: launch snippet and follow onscreen instructions + * Bug description: Swing crashes + * Expected results: Nothing should crash + * GTK Version(s): N/A + */ +public class Bug306490_SwingDisposeError { + + static void createSwing() { + JFrame frame = new JFrame("Swing, close me (before or after closing the other window)"); + frame.setBounds(0, 0, 600, 100); + + frame.addWindowListener(new WindowAdapter() { // same bug with using setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE) instead + @Override + public void windowClosing(WindowEvent e) { + e.getWindow().dispose(); + System.out.println("Swing: disposed"); + } + }); + + // remark 1: comment out the following line (do not add textArea) and all works fine + frame.getContentPane().add(new JTextArea()); + frame.setVisible(true); + } + + static void createSwt() { + Display display = new Display(); + Shell shell = new Shell(display, SWT.TITLE); + shell.setBounds(0, 200, 600, 100); + shell.open(); + while (!shell.isDisposed()) + if (!display.readAndDispatch()) + display.sleep(); + + display.dispose(); + System.out.println("SWT: disposed"); + } + + public static void main(String[] args) throws Exception { + //remark 2: change order of following two instantiations and all works fine + createSwing(); + Thread.sleep(1000); + new Thread() { @Override + public void run() {createSwt();} }.start(); // also createSwt() alone doesn't work + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug307441_DnDOverlappingControls.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug307441_DnDOverlappingControls.java new file mode 100644 index 0000000000..7eff00e018 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug307441_DnDOverlappingControls.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +/* + * Drag and Drop example snippet: drag a URL between two labels. + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.DropTargetListener; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.dnd.URLTransfer; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 307441 - [DND] DnD on Linux does not behave as expected with overlapping controls + * How to run: launch snippet and drag controls from left side to right, watch console for print statements + * Bug description: Improper events for overlapped controls + * Expected results: All events should be fired correctly + * GTK Version(s): all + */ +public class Bug307441_DnDOverlappingControls { + +public static void main (String [] args) { + + Display display = new Display (); + final Shell shell = new Shell (display); + shell.setText("URLTransfer"); + shell.setLayout(new FillLayout()); + final Label label1 = new Label (shell, SWT.BORDER); + label1.setText ("http://www.eclipse.org"); + + final Composite dropComp = new Composite(shell, SWT.BORDER); + dropComp.setSize(600,300); + Rectangle clientArea = dropComp.getClientArea(); + + final Label label2 = new Label (dropComp, SWT.BORDER); + label2.setBackground(new Color(null,255,255,0)); + label2.setText("DropLabel1"); + label2.setSize(100,100); + label2.setBounds(clientArea.x, clientArea.y, clientArea.width, (clientArea.height*2)/3); + + final Label label3 = new Label (dropComp, SWT.BORDER); + label3.setBackground(new Color(null, 255, 0,0)); + label3.setText("DropLabel2"); + label3.setSize(100,100); + label3.setBounds(clientArea.x+10, clientArea.y+clientArea.height/3, clientArea.width-10, clientArea.height/2); + label3.moveAbove(label2); + + setDragSource (label1); + setDropTarget (dropComp); + setDropTargetForLabel (label2); + setDropTargetForLabel (label3); + + shell.setSize(900, 300); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + +public static void setDragSource (final Label label) { + int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; + final DragSource source = new DragSource (label, operations); + source.setTransfer(new Transfer[] {URLTransfer.getInstance()}); + source.addDragListener (new DragSourceListener () { + @Override + public void dragStart(DragSourceEvent e) { + } + @Override + public void dragSetData(DragSourceEvent e) { + e.data = label.getText(); + } + @Override + public void dragFinished(DragSourceEvent event) { + } + }); +} + +public static void setDropTargetForLabel (final Label control) { + int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; + DropTarget target = new DropTarget(control, operations); + target.setTransfer(new Transfer[] {URLTransfer.getInstance()}); + target.addDropListener (new DropTargetListener() { + @Override + public void dragEnter(DropTargetEvent e) { + System.out.println("dragEnter="+control.getText()); + if (e.detail == DND.DROP_NONE) + e.detail = DND.DROP_LINK; + } + @Override + public void dragOperationChanged(DropTargetEvent e) { + if (e.detail == DND.DROP_NONE) + e.detail = DND.DROP_LINK; + } + @Override + public void drop(DropTargetEvent event) { + if (event.data == null) { + event.detail = DND.DROP_NONE; + return; + } + control.setText(((String) event.data)); + + } + @Override + public void dragLeave(DropTargetEvent arg0) { + // TODO Auto-generated method stub + System.out.println("dragLeave="+control.getText()); + + } + @Override + public void dragOver(DropTargetEvent arg0) { + // TODO Auto-generated method stub + + } + @Override + public void dropAccept(DropTargetEvent arg0) { + // TODO Auto-generated method stub + + } + }); +} +public static void setDropTarget (final Control control) { + int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; + DropTarget target = new DropTarget(control, operations); + target.setTransfer(new Transfer[] {URLTransfer.getInstance()}); + target.addDropListener (new DropTargetListener() { + @Override + public void dragEnter(DropTargetEvent e) { + System.out.println("dragEnter=composite"); + + if (e.detail == DND.DROP_NONE) + e.detail = DND.DROP_LINK; + } + @Override + public void dragOperationChanged(DropTargetEvent e) { + if (e.detail == DND.DROP_NONE) + e.detail = DND.DROP_LINK; + } + @Override + public void drop(DropTargetEvent event) { + if (event.data == null) { + event.detail = DND.DROP_NONE; + return; + } + control.setBackground(new Color(null,0,0,255)); + } + @Override + public void dragLeave(DropTargetEvent arg0) { + // TODO Auto-generated method stub + System.out.println("dragLeave=composite"); + + } + @Override + public void dragOver(DropTargetEvent arg0) { + // TODO Auto-generated method stub + + } + @Override + public void dropAccept(DropTargetEvent arg0) { + // TODO Auto-generated method stub + + } + }); +} +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug326117_EmbeddedBrowser.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug326117_EmbeddedBrowser.java new file mode 100644 index 0000000000..24f62743a1 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug326117_EmbeddedBrowser.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Frame; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.JTextField; +import javax.swing.text.JTextComponent; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 326117 - SWT_AWT bridge - SWT in Swing problem + * How to run: launch snippet and try to use the browser widget + * Bug description: Nothing is visible except the text bar + * Expected results: The browser should be rendering web content + * GTK Version(s): GTK2 all + */ +public class Bug326117_EmbeddedBrowser{ + + public static void main(String[] args) + { + final Display display = Display.getDefault(); + + Frame frm = new Frame("MyBrowser"); + Canvas embedded = new Canvas(); + frm.add(embedded, BorderLayout.CENTER); + + frm.pack(); + + final Shell composite = SWT_AWT.new_Shell(display, embedded); + composite.setLayout(new FillLayout(SWT.VERTICAL)); + final Browser browser = installBrowser(composite, "http://www.baidu.com"); + frm.addWindowListener(new WindowAdapter() + { + @Override + public void windowClosing(WindowEvent e) + { + e.getWindow().dispose(); + //composite.dispose(); +// display.dispose(); + } + }); + + JTextField addr = new JTextField(80); + addr.addActionListener(e -> display.syncExec(() -> browser.setUrl(((JTextComponent) e.getSource()).getText()))); + frm.add(addr, BorderLayout.NORTH); + + frm.setSize(800, 600); + frm.setVisible(true); + while (frm.isDisplayable()) + if (!display.readAndDispatch()) + display.sleep(); +// display.dispose(); + } + + public static Browser installBrowser(Composite parent, String homeURL) + { + Browser browser = new Browser(parent, SWT.EMBEDDED); + browser.setUrl(homeURL); + return browser; + } + }
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug35783_DnDMouseExit.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug35783_DnDMouseExit.java new file mode 100644 index 0000000000..59325fe29d --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug35783_DnDMouseExit.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DragSourceAdapter; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 35783 - [DND] Sometimes GTK sends mouse exit during native Drag [portability] + * How to run: Run the snippet and drag quickly + * Bug description: MouseExit events are fired when dragging + * Expected results: No MouseExit events should be fired + * GTK Version(s): ALL + */ +public class Bug35783_DnDMouseExit { + public static void main(String[] args) { + final Display display = Display.getDefault(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + shell.addListener(SWT.MouseExit, event -> System.out.println("exit")); + shell.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + System.out.println("down"); + } + @Override + public void mouseUp(MouseEvent e) { + System.out.println("up"); + } + }); + DragSource ds = new DragSource(shell, DND.DROP_COPY); + ds.setTransfer(new Transfer[] {TextTransfer.getInstance()}); + ds.addDragListener(new DragSourceAdapter() { + @Override + public void dragStart(DragSourceEvent event) { + System.out.println("Drag Start"); + } + }); + shell.open(); + while (!shell.isDisposed()) + if (!display.readAndDispatch()) + display.sleep(); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug465280_InvisibleControlAllocation.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug465280_InvisibleControlAllocation.java new file mode 100644 index 0000000000..622c1bd331 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug465280_InvisibleControlAllocation.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 465280 - [GTK3] OS.gtk_widget_get_allocation returns (0,0) for invisible controls + * How to run: launch snippet and observe coordinates printed in console + * Bug description: The coordinates are (0,0) + * Expected results: The coordinates should not be (0,0) if the widget is hidden. + * GTK Version(s): GTK3.8+ + */ +public class Bug465280_InvisibleControlAllocation { + public static void main(String[] args) { + String property = System.getenv("SWT_GTK3"); + if (property != null) { + System.err.println("GTK"+(property.equals("1")?"3":"2")); + } + Display display = new Display (); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + Label descriptionHint = new Label(shell, SWT.WRAP); + descriptionHint.setText("This is a very very very very very very long string"); + descriptionHint.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + descriptionHint.setVisible(false); + shell.open(); + System.err.println(descriptionHint.getSize()); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug477950_SystemColors.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug477950_SystemColors.java new file mode 100644 index 0000000000..18b0deb468 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug477950_SystemColors.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +/* + * Title: Bug 477950 - [GTK3] Port SWT colors from using GdkColor to GdkRGBA so alpha is not lost + * How to run: launch snippet and compare system colors in the columns + * Bug description: N/A + * Expected results: GTK CSS column with actual output column. Colors should match or be within +/-2 margin of error. + * GTK Version(s): 3.14+ + */ +public class Bug477950_SystemColors { + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + Table table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); + TableColumn name = new TableColumn(table, SWT.NONE); + TableColumn gtkCSSRGBA = new TableColumn(table, SWT.NONE); + TableColumn gtkCSSColor = new TableColumn(table, SWT.NONE); + TableColumn actualColor = new TableColumn(table, SWT.NONE); + TableColumn actualRGBA = new TableColumn(table, SWT.NONE); + name.setText("Color name"); + gtkCSSRGBA.setText("GTK CSS RGBA value"); + gtkCSSColor.setText("GTK CSS color"); + actualColor.setText("Current system color"); + actualRGBA.setText("Current system RGBA value"); + table.setHeaderVisible(true); + table.setLinesVisible(true); + name.setWidth(500); + gtkCSSRGBA.setWidth(150); + gtkCSSColor.setWidth(150); + actualColor.setWidth(150); + actualRGBA.setWidth(150); + Color [] colArray; + Map<String, Color []> map = new HashMap<>(); + colArray = new Color [] {display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW), new Color (display, 0,0,0)}; + map.put("COLOR_WIDGET_DARK_SHADOW", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), new Color (display, 164,164,161)}; + map.put("COLOR_WIDGET_NORMAL_SHADOW", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW), new Color (display, 232,232,231)}; + map.put("COLOR_WIDGET_LIGHT_SHADOW", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW), new Color (display, 255,255,255)}; + map.put("COLOR_WIDGET_HIGHLIGHT_SHADOW", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND), new Color (display, 46,52,54)}; + map.put("COLOR_WIDGET_FOREGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND), new Color (display, 232,232,231)}; + map.put("COLOR_WIDGET_BACKGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_WIDGET_BORDER), new Color (display, 0,0,0)}; + map.put("COLOR_WIDGET_BORDER", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_LIST_FOREGROUND), new Color (display, 0,0,0)}; + map.put("COLOR_LIST_FOREGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_LIST_BACKGROUND), new Color (display, 255,255,255)}; + map.put("COLOR_LIST_BACKGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_LIST_SELECTION), new Color (display, 74,144,217)}; + map.put("COLOR_LIST_SELECTION", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT), new Color (display, 255,255,255)}; + map.put("COLOR_LIST_SELECTION_TEXT", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_INFO_FOREGROUND), new Color (display, 255,255,255)}; + map.put("COLOR_INFO_FOREGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_INFO_BACKGROUND), new Color (display, 0,0,0)}; + map.put("COLOR_INFO_BACKGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND), new Color (display, 255,255,255)}; + map.put("COLOR_TITLE_FOREGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND), new Color (display, 74,144,217)}; + map.put("COLOR_TITLE_BACKGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT), new Color (display, 133,188,246)}; + map.put("COLOR_TITLE_BACKGROUND_GRADIENT", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND), new Color (display, 139,142,143)}; + map.put("COLOR_TITLE_INACTIVE_FOREGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND), new Color (display, 241,241,241)}; + map.put("COLOR_TITLE_INACTIVE_BACKGROUND", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT), new Color (display, 255,255,255)}; + map.put("COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT", colArray); + + colArray = new Color [] {display.getSystemColor(SWT.COLOR_LINK_FOREGROUND), new Color (display, 42,118,198)}; + map.put("COLOR_LINK_FOREGROUND", colArray); + + for (Entry<String, Color[]> entry : map.entrySet()) { + String s = entry.getKey(); + Color gtk = entry.getValue()[1]; + Color current = entry.getValue()[0]; + TableItem item = new TableItem(table, SWT.NONE); + item.setText(0, s); + item.setText(1, "rgb(" + gtk.getRed() + ", " + gtk.getGreen() + ", " + gtk.getBlue() + ")"); + item.setBackground(2, gtk); + item.setBackground(3, current); + item.setText(4, "rgba(" + current.getRed() + ", " + current.getGreen() + ", " + current.getBlue() + ", " + + current.getAlpha() + ")"); + } + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug483097_RegexForegroundTesting.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug483097_RegexForegroundTesting.java new file mode 100644 index 0000000000..3e6907739d --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug483097_RegexForegroundTesting.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/* + * Title: Bug 483097 - [GTK3.16+] gtk_widget_override_color is deprecated + * How to run: launch snippet and check sysout + * Bug description: N/A + * Expected results: if the pattern on line 18 matches: true will be printed + * GTK Version(s): N/A + */ +public class Bug483097_RegexForegroundTesting { + + public static void main(String[] args) { + // Test string + String searched = "* {color: rgb(255, 0, 0);{"; + // Test pattern + String pattern = "[^-]color: rgba?\\((\\d+(,\\s?)?){3,4}"; + Pattern r = Pattern.compile(pattern); + Matcher m = r.matcher(searched); + System.out.println(m.find()); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug483791_setBackgroundGC.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug483791_setBackgroundGC.java new file mode 100644 index 0000000000..adafcedbf7 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug483791_setBackgroundGC.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 483791 - [GTK3] setBackground overrides GC drawing in PaintListener + * How to run: launch snippet and press button "CLICK" + * Bug description: Label will have Cyan background but no line drawn through it + * Expected results: Label should draw line through it regardless of bg color + * GTK Version(s): 3.10+ + */ +public final class Bug483791_setBackgroundGC { + + public static void main(String[] args) { + final Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new GridLayout()); + + final Label l = new Label(shell, SWT.None); + l.setText("ASDQWE"); + l.addPaintListener(arg0 -> arg0.gc.drawLine(0, 0, arg0.width, arg0.height)); + + final Button b = new Button(shell, SWT.PUSH); + b.setText("CLICK"); + b.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent arg0) { + l.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); + // these don't help + /* + l.redraw(); + l.update(); + */ + MessageBox mb = new MessageBox(shell); + mb.setMessage("Background should not override GC drawing, but it does"); + mb.open(); + } + }); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); + } + + private Bug483791_setBackgroundGC() { + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug486068_AllocationWarningsScrollBar.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug486068_AllocationWarningsScrollBar.java new file mode 100644 index 0000000000..6e2b8d4eb5 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug486068_AllocationWarningsScrollBar.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/* + * Title: Bug 486068: [GTK3.20+] Allocation warnings printed in error console + * How to run: launch snippet and check console for warnings + * Bug description: GTK assertion warnings all over the place for GtkScrollbar + * Expected results: clean console output, no warnings + * GTK Version(s): GTK3.20+ + */ +public class Bug486068_AllocationWarningsScrollBar { + + public static void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + Text text = new Text (shell, SWT.V_SCROLL); + text.setBounds(0, 0, 200, 30); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug497705_setBoundsAfterSetVisible.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug497705_setBoundsAfterSetVisible.java new file mode 100644 index 0000000000..de75e12f7e --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug497705_setBoundsAfterSetVisible.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import static org.junit.Assert.assertTrue; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +/** + * Title: Bug 465280 – [GTK3] OS.gtk_widget_get_allocation returns (0,0) for invisible controls + * How to run: These are jUnits. Select the class and run as jUnits. + * Bug description: getBounds is not working properly in combination with setVisible. + * Expected results: All tests should pass, but on Gtk3.8+ the "fails_*" tests fail. + * GTK version(s): GTK3.8+ + * + * This is a snippet to validate upcomming bug submission. These will be used to make new jUnits later. + */ +public class Bug497705_setBoundsAfterSetVisible { + + boolean debugShowWidget = false; // true = see shell & widget. False = tests run without interaction. + + Display display; + Shell shell ; + private StringBuffer log; + private int x; + private int y; + private int height; + private int width; + private boolean passed; + private Rectangle bounds; + Control testControl; + + @Before + public void setUp() { + display = Display.getDefault(); + shell = new Shell(display); + shell.setSize(400, 400); + log = new StringBuffer(""); + x = 5; + y = 10; + height = 100; + width = 200; + passed = true; + testControl = new Button(shell, SWT.PUSH); + } + + @Test + public void fails_test2_setBoundsAfterVisibility() { // Works on Gtk2, Fails on Gtk3. + testControl.setVisible(false); + testControl.setVisible(true); + + testControl.setBounds(x, y, width, height); + + bounds = testControl.getBounds(); + verifyBounds(); + } + @Test + public void fails_test2b_setBoundsInvisibleWidgets() { // Works on Gtk2, Fails on Gtk3. + testControl.setVisible(false); + + testControl.setBounds(x, y, width, height); + + bounds = testControl.getBounds(); + verifyBounds(); + } + + + @Test + public void fails_test3_setBoundsBetweenVisibility() { // Works on Gtk2, Fails on Gtk3. + testControl.setVisible(false); + testControl.setBounds(x, y, width, height); + testControl.setVisible(true); + + bounds = testControl.getBounds(); + verifyBounds(); + } + + @Test + public void fails_moveInnvisibleControl() { + testControl.setBounds(4, 4, 6, 6); + + shell.open(); for (int i = 0; i < 500; i++) display.readAndDispatch(); + testControl.setVisible(false); + shell.open(); for (int i = 0; i < 500; i++) display.readAndDispatch(); + testControl.setBounds(x, y, width, height); + shell.open(); for (int i = 0; i < 500; i++) display.readAndDispatch(); + testControl.setVisible(true); + shell.open(); for (int i = 0; i < 500; i++) display.readAndDispatch(); + + bounds = testControl.getBounds(); // Visually looks ok. (width/height), but programatically incorrect getBounds(). + verifyBounds(); + } + + @Test + public void fails_unecessaryEvents() { // Breaks on Gtk3.8 & onwards + testControl.setVisible(false); + + AtomicInteger resizeCount = new AtomicInteger(0); + AtomicInteger moveCount = new AtomicInteger(0); + + testControl.addControlListener(new ControlListener() { + @Override + public void controlResized(ControlEvent e) { + resizeCount.incrementAndGet(); + } + @Override + public void controlMoved(ControlEvent e) { + moveCount.incrementAndGet(); + } + }); + + for (int i = 0; i < 10; i++) { + testControl.setBounds(x, y, width, height); // Once bounds set, calling same bounds shouldn't trigger SWT.MOVE events. + } + if (resizeCount.get() != 1 || moveCount.get() != 1) { + passed = false; + log.append("\nERROR:\nExpected only one Resize and one Move event.\nActually received R/M:" + resizeCount.get() + "/" + moveCount.get()); + } + } + + @Test + public void works_test1_setBoundsBeforeVisibility () { + // Note, here you can see that getBounds() does work for widgets that are set to be invisible, but + // only if setBounds was called before setVisible(false). + // The problem is inside setBounds, if it's called after setVisible(false), then getBounds() returns wrong output. + testControl.setBounds(x, y, width, height); + + testControl.setVisible(false); +// testControl.setVisible(true); // commenting or uncommenting this doesn't change anything. + + bounds = testControl.getBounds(); + verifyBounds(); + } + + @Test + public void works_zeroSize() { // There has to be a mechanism by which we set with and height to 0. + testControl.setBounds(x, y, width, height); + x = y = width = height = 0; + testControl.setBounds(x, y, width, height); + bounds = testControl.getBounds(); + verifyBounds(); + } + + @Test + public void works_drainingQueue() { + testControl.setVisible(false); + testControl.setVisible(true); + + // doing readAndDispatch up *before* 'setBounds()' doesn't make a difference. + testControl.setBounds(x, y, width, height); + + // doing readAndDispatch *After* setBounds *many times* gives gtk time to update it's cache, and getBounds() returns correct coordinates. + shell.open(); + for (int i = 0; i < 1000; i++) + display.readAndDispatch(); + + bounds = testControl.getBounds(); + verifyBounds(); + } + + @After + public void tearDown() { + if (debugShowWidget) { + if (!passed) System.err.println(log.toString()); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + assertTrue(log.toString(), passed); + } + + private void verifyBounds() { + if (bounds.x != x | bounds.y != y) { + passed = false; + log.append("\nERROR: x,y do not match. Expected:" + x + "/" + y + " Actual:" + bounds.x + "/" + bounds.y); + } + if (bounds.height != height | bounds.width != width) { + passed = false; + log.append("\nERROR: width,height do not match. Expected:" + width + "/" + height + " Actual:" + + bounds.width + "/" + bounds.height); + } + } + +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug500703_ComboGarbledResize.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug500703_ComboGarbledResize.java new file mode 100644 index 0000000000..6c373985c0 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug500703_ComboGarbledResize.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 500703 - [GTK3.20+] Combo with SWT.READ_ONLY is garbled upon re-size + * How to run: launch snippet, select long box, start to shrink window + * Bug description: Text is drawn over itself numerous times, causing garbled text + * Expected results: Text should shrink and not be drawn over other widgets + * GTK Version(s): 3.20+ + */ +public class Bug500703_ComboGarbledResize { + + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new GridLayout(2, false)); + + Label label = new Label(shell, SWT.NONE); + label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false,false, 1, 1)); + label.setText("Testing Label"); + + Combo text = new Combo(shell, SWT.READ_ONLY); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + text.add("This is a very long long long long long box"); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug509514_IncorrectToDisplayLocation.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug509514_IncorrectToDisplayLocation.java new file mode 100644 index 0000000000..3da58db495 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug509514_IncorrectToDisplayLocation.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * @author Thomas Singer + */ +/* + * Title: Bug 509514 - GTK3: Incorrect calculation of Combo location (toDisplay) + * How to run: launch snippet, edit the Combo or Text box, press space + * Bug description: A popup appears under the Text widget but not the Combo + * Expected results: A popup should appear under the widget being edited + * GTK Version(s): 3 + */ +public class Bug509514_IncorrectToDisplayLocation { + + public static void main(String[] args) { + final Display display = new Display(); + final Shell shell = new Shell(display); + + final RowLayout layout = new RowLayout(SWT.VERTICAL); + layout.fill = true; + shell.setLayout(layout); + + final Combo combo = new Combo(shell, SWT.BORDER); + installPopup(combo); + + final Text text = new Text(shell, SWT.BORDER); + installPopup(text); + + shell.setSize(400, 300); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); + } + + private static void installPopup(Control control) { + final Listener listener = new Listener() { + private Shell shell; + + @Override + public void handleEvent(Event event) { + if (event.type == SWT.KeyDown) { + if (event.character == ' ') { + shell = new Shell(control.getShell(), SWT.POP_UP | SWT.ON_TOP | SWT.BORDER); + final Point location = control.toDisplay(0, control.getSize().y); + shell.setBounds(location.x, location.y, 100, 100); + shell.setVisible(true); + } + } else if (event.type == SWT.FocusOut) { + if (shell != null) { + shell.dispose(); + shell = null; + } + } + } + }; + control.addListener(SWT.KeyDown, listener); + control.addListener(SWT.FocusOut, listener); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug510803_TabFolder_Table_inPlaceEditing.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug510803_TabFolder_Table_inPlaceEditing.java new file mode 100644 index 0000000000..aa8a2e6b02 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug510803_TabFolder_Table_inPlaceEditing.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; + +/* + * Title: + * How to run: + * Bug description: + * Expected results: + * GTK Version(s): + */ +//clicking on a row item and typing appends characters. +//Gtk2: Works as expected. +//Gtk3: Spam of errors, black second window. +//(SWT:7324): Gdk-WARNING **: gdk_window_new(): parent is destroyed +//(SWT:7324): Gdk-CRITICAL **: gdk_window_set_user_data: assertion 'GDK_IS_WINDOW (window)' failed +//(SWT:7324): Gdk-CRITICAL **: gdk_window_get_scale_factor: assertion 'GDK_IS_WINDOW (window)' failed +//(SWT:7324): GLib-GObject-CRITICAL **: g_object_ref: assertion 'G_IS_OBJECT (object)' failed +public class Bug510803_TabFolder_Table_inPlaceEditing { + + public static void main(String[] args) { + Shell shell = shellSetup(); + + final TabFolder tabFolder = new TabFolder(shell, SWT.NONE); + TabItem tabItem = new TabItem(tabFolder, SWT.NONE); + tabItem.setText("Hello tab"); + + Table table = new Table(tabFolder, SWT.NONE); + TableItem tableItem = new TableItem(table, SWT.None); + tableItem.setText("Item 1"); + TableItem tableItem2 = new TableItem(table, SWT.None); + tableItem2.setText("Item 2"); + + // Notes: + // - Seems to occur with any control, not just Text. (Tested with Button also) + final Text cellEditorText = new Text(table, SWT.SINGLE); // Note, + cellEditorText.setText("Hello world"); + + // Listeners that make typing into Table edit controls. Useful to test + // functionality, but errors occur without the listeners also. + table.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + cellEditorText.setFocus(); + }; + }); + + cellEditorText.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + TableItem selectedItem = table.getSelection()[0]; + selectedItem.setText(selectedItem.getText() + e.character); + }; + }); + + // Location of setControl() method call has an impact. + // If it's before 'Text' creation, no errors are thrown into the + // console. + tabItem.setControl(table); + + mainEventLoop(shell); + } + + private static Shell shellSetup() { + final Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + return shell; + } + + private static void mainEventLoop(Shell shell) { + Display display = shell.getDisplay(); + shell.open(); + shell.setSize(200, 300); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_JsConsole.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_JsConsole.java new file mode 100644 index 0000000000..4707f51c11 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_JsConsole.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.BrowserFunction; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/* + * Title: [GTK3][Webkit2] Implement webkit2 support for browser function (Part 2: Java return a value from callback.) + * How to run: Snippet to execute javascript via input prompt, to test Browser Func return value ability. + * Bug description: + * Expected results: + * GTK Version(s): + */ +public class Bug510905_Browser_JsConsole { + + static int count = 0; + + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setSize(500, 600); + + GridLayout gridLayout = new GridLayout(); + shell.setLayout(gridLayout); + + final Text jsConsole = new Text(shell, SWT.BORDER); +// jsConsole.setText("document.body.innerHTML = theJavaFunction(123, 'hello', null, true)"); + jsConsole.setText("document.body.innerHTML = theJavaFunction()"); // Case where there are no paramaters. + jsConsole.setSelection(jsConsole.getText().length()); + GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + jsConsole.setLayoutData(data); + + final Browser browser = new Browser(shell, SWT.NONE); + browser.setText("hello <b>world!</b>"); + data = new GridData(SWT.FILL, SWT.FILL, true, true); + browser.setLayoutData(data); + + jsConsole.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.keyCode == 13) { // 13 = Enter + browser.execute(jsConsole.getText()); + } + } + }); + + Button loadNewPage = new Button(shell, SWT.PUSH); + loadNewPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + loadNewPage.setText("Load new Page"); + loadNewPage.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + browser.setText("New page!" + count++); + } + }); + + + // BrowserFunction Code + @SuppressWarnings("unused") + final BrowserFunction function = new CustomFunction (browser, "theJavaFunction"); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + + static class CustomFunction extends BrowserFunction { // copied from snippet 307 + CustomFunction (Browser browser, String name) { + super (browser, name); + } + @Override + public Object function (Object[] arguments) { + System.out.println ("theJavaFunction() called from javascript with args:"); + for (int i = 0; i < arguments.length; i++) { + Object arg = arguments[i]; + if (arg == null) { + System.out.println ("\t-->null"); + } else { + System.out.println ("\t-->" + arg.getClass ().getName () + ": " + arg.toString ()); + } + } + return arguments; +// return new Point(1, 2); + +// Object returnValue = new Object[] { +// new Short ((short)3), +// new Boolean (true), +// null, +// new Object[] {"a string", new Boolean (false)}, +// "hi", +// new Float (2.0f / 3.0f), +// }; +// return returnValue; + +// return new Double(42.0); + } + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_TwoJsConsoles.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_TwoJsConsoles.java new file mode 100644 index 0000000000..017be8f1b9 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_TwoJsConsoles.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.BrowserFunction; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/* + * Title: [GTK3][Webkit2] Implement webkit2 support for browser function (Part 2: Java return a value from callback.) + * How to run: Snippet to execute javascript via input prompt, to test Browser Func return value ability. + * Bug description: + * Expected results: + * GTK Version(s): + */ +public class Bug510905_Browser_TwoJsConsoles { + + static int count = 0; + + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setSize(500, 600); + + shell.setLayout(new RowLayout()); + + Composite leftBrowser = new Composite(shell, SWT.NONE); + Composite rightBrowser = new Composite(shell, SWT.None); + Button button = new Button (rightBrowser, SWT.PUSH); + button.setText("my button"); + + + final Browser browser = makeBrowserWithConsole(leftBrowser, "theJavaFunction"); + new CustomFunction (browser, "theJavaFunction"); + + final Browser browser2 = makeBrowserWithConsole(rightBrowser, "theJavaFunction"); + new CustomFunction (browser2, "theJavaFunction"); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + + /** + * @param leftBrowser + * @return + */ + private static Browser makeBrowserWithConsole(Composite leftBrowser, String funcName) { + GridLayout gridLayout = new GridLayout(); + leftBrowser.setLayout(gridLayout); + + final Text jsConsole = new Text(leftBrowser, SWT.BORDER); + jsConsole.setText("document.body.innerHTML = " + funcName + "(123)"); // Case where there are no paramaters. + jsConsole.setSelection(jsConsole.getText().length()); + GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + jsConsole.setLayoutData(data); + + final Browser browser = new Browser(leftBrowser, SWT.NONE); + browser.setText("hello <b>world!</b>"); + data = new GridData(SWT.FILL, SWT.FILL, true, true); + browser.setLayoutData(data); + + jsConsole.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.keyCode == 13) { // 13 = Enter + browser.execute(jsConsole.getText()); + } + } + }); + + Button loadNewPage = new Button(leftBrowser, SWT.PUSH); + loadNewPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + loadNewPage.setText("Load new Page"); + loadNewPage.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + browser.setText("New page!" + count++); + } + }); + return browser; + } + + static class CustomFunction extends BrowserFunction { // copied from snippet 307 + CustomFunction (Browser browser, String name) { + super (browser, name); + } + @Override + public Object function (Object[] arguments) { + System.out.println ("theJavaFunction() called from javascript with args:"); + for (int i = 0; i < arguments.length; i++) { + Object arg = arguments[i]; + if (arg == null) { + System.out.println ("\t-->null"); + } else { + System.out.println ("\t-->" + arg.getClass ().getName () + ": " + arg.toString ()); + } + } + return arguments; + } + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug514483_getCursorLocation.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug514483_getCursorLocation.java new file mode 100644 index 0000000000..f651809aea --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug514483_getCursorLocation.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + + +/* + * Title: Bug 514483 - [wayland] Launchbar filter closes when clicked + * How to run: launch snippet and follow onscreen instructions + * Bug description: The X-Y coordinates are relative to the child shell. + * Expected results: The X-Y coordinates are relative to the parent shell. + * GTK Version(s): GTK3.16+ (Wayland) + */ +public class Bug514483_getCursorLocation +{ + public static void main(String[] args) + { + final Display display = new Display(); + Shell shell = new Shell(display); + shell.setBounds(0, 0, 600, 600); + + Label parentShellLabel = new Label(shell, SWT.None); + parentShellLabel.setText("Parent widget.shell.\n" + + "INSTRUCTIONS:\n" + + "- Parent widget.shell should be maximized.\n" + + "- Child widget.shell should be at x400 y400 (in yellow square).\n" + + "- Click inside the child widget.shell, observe result coordinates below.\n" + + "\n" + + "The bug is that x,y is not relative to parent, but relative to child-widget.shell itself (0-200 range).\n" + + "Expected coordinates: between ~400 to ~600. (i.e, relative to parent's x,y.)\n" + + "Result Coordinates:"); + parentShellLabel.setBounds(0, 0, 600, 200); + + final Label resultLbl = new Label(shell, SWT.None); + resultLbl.setBounds(0,180, 600, 100); + resultLbl.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); + + Label childShellLocation = new Label(shell, SWT.None); + childShellLocation.setText("Child Shell should be here.\nIf it is not, move it here \nmanually"); + childShellLocation.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); + childShellLocation.setBounds(400, 400, 200, 160); + + Shell childShell = new Shell(shell, SWT.ON_TOP); + childShell.setBackground(display.getSystemColor(SWT.COLOR_DARK_YELLOW)); + + MouseAdapter clickListener = new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + Point loc = display.getCursorLocation(); + resultLbl.setText(loc.toString()); + if (loc.x > 300 && loc.x < 700 && loc.y > 300 && loc.y < 700) // give user some slack. + resultLbl.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); + else + resultLbl.setBackground(display.getSystemColor(SWT.COLOR_RED)); + } + }; + childShell.addMouseListener(clickListener); + +// display.addFilter(SWT.KeyDown, new Listener() { +// public void handleEvent(Event e) { +// if (e.type == SWT.KeyDown) { +// switch (e.keyCode) { +// case SWT.F1: +// System.out.println("Passed"); +// break; +// case SWT.F2: +// System.out.println("Failed"); +// break; +// case SWT.F3: +// System.out.println("Skipped"); +// break; +// case SWT.F4: +// System.out.println("Exit Test suite"); +// break; +// } +// } +// } +// }); + + shell.open(); + childShell.open(); + childShell.setBounds(400, 400, 200, 200); + while (!shell.isDisposed()) + { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug515915_ScrolledCompositeCTabFolder.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug515915_ScrolledCompositeCTabFolder.java new file mode 100644 index 0000000000..09581cd080 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug515915_ScrolledCompositeCTabFolder.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 515915 - [GTK3] ScrolledComposite within CTabFolder does not show scrollbars until resize + * How to run: launch snippet and observe scrollbar area + * Bug description: The scrollbar does not appear until the window is resized + * Expected results: The scrollbar appears immediately when the snippet runs + * GTK Version(s): GTK3 + */ +public class Bug515915_ScrolledCompositeCTabFolder +{ + public static void main(String[] args) + { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + shell.setSize(100, 150); + + CTabFolder tabFolder = new CTabFolder(shell, SWT.NONE); + tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE); + tabItem.setText("Tab"); + + ScrolledComposite scroller = new ScrolledComposite(tabFolder, SWT.V_SCROLL | SWT.H_SCROLL); + scroller.setExpandHorizontal(true); + scroller.setExpandVertical(true); + tabItem.setControl(scroller); + + Label label = new Label(scroller, SWT.NONE); + label.setText("Label\n with\n a\n tall\n text\n string\n inside\n of\n it."); + label.pack(); + + scroller.setContent(label); + scroller.setMinSize(label.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + + shell.open(); + + while (!shell.isDisposed()) + { + if (!display.readAndDispatch()) + { + display.sleep(); + } + } + + display.dispose(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug518961_RTTest.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug518961_RTTest.java new file mode 100644 index 0000000000..41a2d29832 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug518961_RTTest.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + + +/** + * + To get this guy to work, + 1) Uncomment line with "UNCOMMENT THIS". + 2) Get hold of nebula rich text project. (found inside org.eclipse.nebula) + edit .classpath and add: + <classpathentry kind="src" path="/org.eclipse.nebula.widgets.richtext"/> + (This can be done via auto fix. + + Before Fix: When running, error messages thrown into console. + After fix: Snippet runs as expected. + */ +public class Bug518961_RTTest extends org.eclipse.swt.widgets.Shell { + + public Bug518961_RTTest(Display display) { + super(display, SWT.SHELL_TRIM); + createContents(); + } + + private void createContents() { +// new RichTextEditor(this); /// UNCOMMENT THIS. + } + + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Bug518961_RTTest(display); + shell.setSize(800, 800); + shell.setLayout(new FillLayout()); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + + @Override + protected void checkSubclass() { + } + +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug519295_TableMultipleColumns.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug519295_TableMultipleColumns.java new file mode 100644 index 0000000000..f5c4a861e1 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug519295_TableMultipleColumns.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +/* + * Title: Bug 519295: [GTK3] Invisible settings button in validation preferences + * How to run: launch snippet and observe TableItem columns + * Bug description: Image only appears in one column + * Expected results: Images should appear at least once in all columns + * GTK Version(s): GTK3 + */ +public class Bug519295_TableMultipleColumns { + public static void main(String[] args) { + Display display = Display.getDefault(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + + Table tree = new Table(shell, SWT.NONE); + tree.setHeaderVisible(true); + + TableColumn column1 = new TableColumn(tree, SWT.LEFT); + column1.setText("Column 1"); + column1.setWidth(50); + TableColumn column2 = new TableColumn(tree, SWT.LEFT); + column2.setText("Column 2"); + column2.setWidth(50); + TableColumn column3 = new TableColumn(tree, SWT.LEFT); + column3.setText("Column 3"); + column3.setWidth(50); + + int W = 100, H = 100; + final Image xImage = new Image(display, W, H); + GC gc = new GC(xImage); + gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); + gc.drawLine(0, 0, W - 1, H - 1); + gc.drawLine(0, H - 1, W - 1, 0); + gc.drawOval(1, 1, W - 2, H - 2); + gc.dispose(); + + int Wz = 40, Hz = 40; + final Image zImage = new Image(display, Wz, Hz); + GC gcz = new GC(zImage); + gcz.setForeground(display.getSystemColor(SWT.COLOR_RED)); + gcz.drawLine(0, 0, Wz - 1, Hz - 1); + gcz.drawLine(0, Hz - 1, Wz - 1, 0); + gcz.drawOval(1, 1, Wz - 2, Hz - 2); + gcz.dispose(); + + for (int i = 0; i < 12; i++) { + if (i != 3 && i != 6) { + TableItem item = new TableItem(tree, SWT.NONE); + item.setImage(i, xImage); + item.setText(i, "Test"); + } + } + + shell.pack(); + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } + +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug519996_focusDisposeIssue.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug519996_focusDisposeIssue.java new file mode 100644 index 0000000000..a4e988db08 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug519996_focusDisposeIssue.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +public class Bug519996_focusDisposeIssue { + + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + CCombo combo = new CCombo(shell, SWT.BORDER); + new CCombo(shell, SWT.BORDER); + + Button button = new Button(shell, SWT.PUSH); + button.setText("focus and close"); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + combo.setFocus(); + shell.close(); + } + }); + + shell.layout(); + shell.open(); + + Display display = shell.getDisplay(); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); + } + +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug525305_Browser_OpenUrl.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug525305_Browser_OpenUrl.java new file mode 100644 index 0000000000..4e1443f34d --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug525305_Browser_OpenUrl.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Handle files or URLs from eclipse launcher or gdbus. + * How to run: + * - Launch snippet. + * - In terminal, run like: + * gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.FileOpen "['/tmp/hi','http://www.eclipse.org']" + * - Expect output: + * "OpenUrl with .. " + * "OpenDocument with .. " + * Bug description: + * Expected results: Browser opens URLs, filenames printed. + * GTK Version(s): 3.22/2.24 + */ +public class Bug525305_Browser_OpenUrl { + + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setSize(500, 600); + shell.setLayout(new FillLayout()); + + final Browser browser = new Browser(shell, SWT.NONE); + browser.setText("hello <b>world!</b>"); + + display.addListener(SWT.OpenUrl, e -> { + System.out.println("OpenUrl with:" + e.text); + browser.setUrl(e.text); + }); + + display.addListener(SWT.OpenDocument, e -> { + System.out.println("OpenDocument with: " + e.text); + browser.setText("OpenDocument was called with arg: " + e.text); + }); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug525946_DownloadFunction.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug525946_DownloadFunction.java new file mode 100644 index 0000000000..695504071d --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug525946_DownloadFunction.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 459462 - [WebKit] Implement Download functionality + * How to run: launch snippet + * Bug description: Download functionality doesn't work on WebKit2. + * Expected results: Download functionality now works on WebKit2. + * GTK version(s): GTK3.x + */ + +public class Bug525946_DownloadFunction { +public static void main(String[] args) { +final Display display = new Display(); +final Shell shell = new Shell(display); +shell.setBounds(10, 10, 400, 400); +shell.setLayout(new FillLayout()); +final Browser browser = new Browser(shell, SWT.NONE); +browser.setUrl("http://download.eclipse.org/tools/orbit/downloads/drops/R20170516192513/orbit-buildrepo-R20170516192513.zip"); +shell.open(); +while (!shell.isDisposed()) { +if (!display.readAndDispatch()) display.sleep(); +} +shell.dispose(); +display.dispose(); +} +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug526083_MenuGetBounds.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug526083_MenuGetBounds.java new file mode 100644 index 0000000000..b7aa12fae9 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug526083_MenuGetBounds.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +//package org.eclipse.swt.tests.gtk.snippets; +// +//import java.lang.reflect.Field; +//import java.lang.reflect.InvocationTargetException; +//import java.lang.reflect.Method; +// +//import org.eclipse.swt.SWT; +//import org.eclipse.swt.graphics.Rectangle; +//import org.eclipse.swt.internal.gtk.GTK; +//import org.eclipse.swt.internal.gtk.GtkAllocation; +//import org.eclipse.swt.internal.gtk.OS; +//import org.eclipse.swt.layout.GridData; +//import org.eclipse.swt.layout.GridLayout; +//import org.eclipse.swt.widgets.Composite; +//import org.eclipse.swt.widgets.Display; +//import org.eclipse.swt.widgets.Menu; +//import org.eclipse.swt.widgets.MenuItem; +//import org.eclipse.swt.widgets.Shell; +//import org.eclipse.swt.widgets.Widget; +// +// +///* +// * Title: Bug 526083 - [GTK3] Menu.getBounds() returns wrong x & y coordinate +// * How to run: launch snippet, right click in the boxes, observe messages printed in the console +// * Bug description: The "getBounds" line has incorrect values +// * Expected results: The "getBounds" line should have the same values as the "correct bounds" line +// * GTK Version(s): GTK3 +// */ +//public class Bug526083_MenuGetBounds { +// +// public static void main(String[] args) { +// final Display display = new Display(); +// Shell shell = new Shell(display); +// shell.setLayout(new GridLayout(2, false)); +// Composite c1 = new Composite(shell, SWT.BORDER); +// c1.setLayoutData(new GridData(100, 100)); +// Composite c2 = new Composite(shell, SWT.BORDER); +// c2.setLayoutData(new GridData(100, 100)); +// final Menu menu = new Menu(shell, SWT.POP_UP); +// MenuItem item = new MenuItem(menu, SWT.PUSH); +// item.setText("Popup"); +// menu.addListener(SWT.Show, event -> display.asyncExec(() -> { +// try { +// // menu.getBounds call +// System.err.println("getBounds: " + invoke(menu, "getBounds")); +// System.err.println("-----------------------------------------"); +// // menu.getBounds implementation +//// long /*int*/ window = gtk_widget_get_window (menu.handle); +// long /*int*/ window = ((Long)invoke(Widget.class, "gtk_widget_get_window", true, menu, new Object[] { Long.valueOf(menu.handle) })).longValue(); +// int [] origin_x = new int [1], origin_y = new int [1]; +// OS.gdk_window_get_origin (window, origin_x, origin_y); +// GtkAllocation allocation = new GtkAllocation (); +// GTK.gtk_widget_get_allocation (menu.handle, allocation); +// System.err.println(origin_x[0] + " " + origin_y[0] + " " + allocation.x + " " + allocation.y + " " + allocation.width + " " + allocation.height); +// int x = origin_x [0] + allocation.x; +// int y = origin_y [0] + allocation.y; +// int width = allocation.width; +// int height = allocation.height; +// Rectangle bounds = new Rectangle (x, y, width, height); +// System.err.println("allocation: " + allocation.x + " " + allocation.y + " " + allocation.width + " " + allocation.height); +// System.err.println("bounds: " + bounds); +// System.err.println("-----------------------------------------"); +// // correct bounds (without allocation) +// x = origin_x [0]; +// y = origin_y [0]; +// bounds = new Rectangle (x, y, width, height); +// System.err.println("correct bounds: " + bounds); +// } catch (Throwable t) { +// t.printStackTrace(); +// } +// })); +// c1.setMenu(menu); +// c2.setMenu(menu); +// shell.setMenu(menu); +// shell.setSize(300, 300); +// shell.setLocation(100, 100); +// shell.open(); +// while (!shell.isDisposed()) { +// if (!display.readAndDispatch()) +// display.sleep(); +// } +// display.dispose(); +// } +// +// public final static Object invoke(final String clazzName, final String methodName, final Object... args) +// throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { +// return invoke(clazzName, methodName, false, args); +// } +// +// public final static Object invoke(final String clazzName, final String methodName, final Class<?>[] params, final Object... args) +// throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { +// return invoke(Class.forName(clazzName), methodName, false, null, params, args); +// } +// +// public final static Object invoke(final String clazzName, final String methodName, final boolean declaredMethod, final Object... args) +// throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { +// return invoke(Class.forName(clazzName), methodName, declaredMethod, null, args); +// } +// +// public final static Object invoke(final Object obj, final String methodName, final Object... args) +// throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { +// return invoke(obj.getClass(), methodName, true, obj, args); +// } +// +// public final static Object invoke(final Class<?> clazz, final String methodName, final boolean declaredMethod, final Object obj, final Object... args) +// throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { +// Class<?>[] params = new Class[args.length]; +// for (int i = 0; i < args.length; i++) { +// Class<?> argClazz = args[i].getClass(); +// try { +// Field typeField = argClazz.getField("TYPE"); //$NON-NLS-1$ +// params[i] = (Class<?>) typeField.get(null); +// } catch (NoSuchFieldException e) { +// params[i] = argClazz; +// } +// } +// return invoke(clazz, methodName, declaredMethod, obj, params, args); +// } +// +// public final static Object invoke(final Class<?> clazz, final String methodName, final boolean declaredMethod, final Object obj, final Class<?>[] params, final Object... args) +// throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { +// Method method; +// if (declaredMethod) { +// method = clazz.getDeclaredMethod(methodName, params); +// method.setAccessible(true); +// } else { +// method = clazz.getMethod(methodName, params); +// } +// return method.invoke(obj, args); +// } +// +//}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528155_TableTreeForegroundDrawing.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528155_TableTreeForegroundDrawing.java new file mode 100644 index 0000000000..2ccdc3e171 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528155_TableTreeForegroundDrawing.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; + +/* + * Title: Bug 528155: [GTK] Table/Tree forgets to set SWT.SELECTED bit on PaintItem + * How to run: launch snippet and click the first row of either Table/Tree widget + * Bug description: The red selection foreground color is not displayed for either Table/Tree + * Expected results: The selected items of each widget should have a red foreground color + * GTK Version(s): GTK2, GTK3 + */ +public class Bug528155_TableTreeForegroundDrawing { + + public static void main(String[] args) { + final Display display = new Display(); + + final Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + + final Color defaultBack = display.getSystemColor(SWT.COLOR_YELLOW); + final Color defaultFore = display.getSystemColor(SWT.COLOR_DARK_GRAY); + final Color selectionBack = display.getSystemColor(SWT.COLOR_BLUE); + final Color selectionBackUnfocused = display.getSystemColor(SWT.COLOR_GRAY); + final Color selectionFore = display.getSystemColor(SWT.COLOR_RED); + + final Tree tree = new Tree(shell, SWT.BORDER); + tree.setBackground(defaultBack); + tree.setForeground(defaultFore); + final Listener treeListener = event -> { + if (event.type == SWT.MeasureItem) { + event.width = 50; + } + else if (event.type == SWT.EraseItem) { + if ((event.detail & SWT.SELECTED) != 0) { + event.gc.setBackground(tree.isFocusControl() ? selectionBack : selectionBackUnfocused); + event.gc.fillRectangle(event.x, event.y, event.width, event.height); + event.detail &= ~SWT.SELECTED; + } + } + else if (event.type == SWT.PaintItem) { + if ((event.detail & SWT.SELECTED) != 0) { + event.gc.setForeground(selectionFore); + } + event.gc.drawString("Node " + event.index, event.x, event.y, true); + } + }; + tree.addListener(SWT.MeasureItem, treeListener); + tree.addListener(SWT.EraseItem, treeListener); + tree.addListener(SWT.PaintItem, treeListener); + + new TreeItem(tree, SWT.NONE); + new TreeItem(tree, SWT.NONE); + + final Table table = new Table(shell, SWT.BORDER | SWT.VIRTUAL); + table.setBackground(defaultBack); + table.setForeground(defaultFore); + table.setHeaderVisible(true); + + final TableColumn column = new TableColumn(table, SWT.LEFT); + column.setText("Column 1"); + column.setWidth(400); + + final Listener tableListener = event -> { + if (event.type == SWT.MeasureItem) { + event.width = 50; + } + else if (event.type == SWT.EraseItem) { + if ((event.detail & SWT.SELECTED) != 0) { + event.gc.setBackground(table.isFocusControl() ? selectionBack : selectionBackUnfocused); + event.gc.fillRectangle(event.x, event.y, event.width, event.height); +// cachedDetail = event.detail; + event.detail &= ~SWT.SELECTED; + } + } + else if (event.type == SWT.PaintItem) { +// if ((cachedDetail & SWT.SELECTED) != 0) { + if ((event.detail & SWT.SELECTED) != 0) { + event.gc.setForeground(selectionFore); + } + event.gc.drawString("Row " + event.index, event.x, event.y, true); + } + else if (event.type == SWT.SetData) { + } + }; + table.addListener(SWT.SetData, tableListener); + table.addListener(SWT.MeasureItem, tableListener); + table.addListener(SWT.EraseItem, tableListener); + table.addListener(SWT.PaintItem, tableListener); + + table.setItemCount(2); + + shell.setSize(500, 400); + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + display.dispose(); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528284_TCFToolBarIssue.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528284_TCFToolBarIssue.java new file mode 100644 index 0000000000..2840839085 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528284_TCFToolBarIssue.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; + +/* + * Title: Bug 528284: [GTK3] Toolbar: TCF dropdown control is cutoff + * How to run: launch snippet and observe ToolBar inside the Shell + * Bug description: the Label and Button are cut off on the bottom + * Expected results: the Label and Button should be displayed as expected + * GTK Version(s): GTK3 + */ +public class Bug528284_TCFToolBarIssue { + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + ToolBar bar = new ToolBar (shell, SWT.HORIZONTAL); + + Composite panel = new Composite(bar, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = 1; layout.marginWidth = 1; + panel.setLayout(layout); + + + Composite labelPanel = new Composite(panel, SWT.BORDER); + labelPanel.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); + GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + labelPanel.setLayoutData(layoutData); + layout = new GridLayout(3, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.horizontalSpacing = 0; + labelPanel.setLayout(layout); + + Label image = new Label(labelPanel, SWT.NONE); + layoutData = new GridData(SWT.LEAD, SWT.CENTER, false, true); + layoutData.horizontalIndent = 1; + layoutData.minimumWidth=20; + layoutData.widthHint=20; + image.setLayoutData(layoutData); + + Label text = new Label(labelPanel, SWT.NONE); + layoutData = new GridData(SWT.FILL, SWT.CENTER, true, true); + layoutData.minimumWidth = 25; + text.setLayoutData(layoutData); + + Button button = new Button(labelPanel, SWT.ARROW | SWT.DOWN | SWT.FLAT | SWT.NO_FOCUS); + layoutData = new GridData(SWT.TRAIL, SWT.CENTER, false, true); + layoutData.minimumWidth=20; + layoutData.widthHint = 20; + button.setLayoutData(layoutData); + + text.setText("this is a test"); + + + ToolItem item = new ToolItem(bar, SWT.SEPARATOR); + item.setControl(panel); + item.setWidth(panel.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); + + bar.pack(); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); + + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528549_browser_MouseFocusEventListeners.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528549_browser_MouseFocusEventListeners.java new file mode 100644 index 0000000000..5855cb6417 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528549_browser_MouseFocusEventListeners.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/** + * On Webkit2, mouseUp/Down were not working. + * On Webkit1/2, Focus in/out were not working. + * + * Snippet prints events to console. Run and observer. + * + * On webkit1, signals were partially handled via javascript, on webkit2 only through gdk events. + * + */ +public class Bug528549_browser_MouseFocusEventListeners { + + static int loadCounter; + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + shell.setSize(500, 200); + final Browser browser = new Browser(shell, SWT.NONE); + + browser.addFocusListener(new FocusListener() { + @Override + public void focusLost(FocusEvent e) { + System.out.println("Browser Focus lost " + e.toString()); + } + @Override + public void focusGained(FocusEvent e) { + System.out.println("Browser Focus gained " + e.toString()); + } + }); + + browser.addMouseListener(new MouseListener() { + @Override + public void mouseUp(MouseEvent e) { + System.out.println("Browser Mouse Up " + e.toString()); + } + @Override + public void mouseDown(MouseEvent e) { + System.out.println("Browser Mouse Down " + e.toString()); + + } + @Override + public void mouseDoubleClick(MouseEvent e) { + System.out.println("Browse Mouse Double click " + e.toString()); + } + }); + + + // Below listeners already worked before bug. But good to have around. + browser.addKeyListener(new KeyListener() { + @Override + public void keyReleased(KeyEvent e) { + System.out.println("Browser key released " + e.toString()); + } + @Override + public void keyPressed(KeyEvent e) { + System.out.println("Browser key pressed " + e.toString()); + } + }); + + browser.addMouseWheelListener(e -> System.out.println("Browser scroll event " + e.toString())); + + // Generates a lot of events... + browser.addMouseMoveListener(e -> System.out.println("Browser mouse moved " + e.toString())); + + Button jsOnButton = new Button(shell, SWT.PUSH); + jsOnButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + jsOnButton.setText("JS Off"); + jsOnButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(false))); + + Button jsOffButton = new Button(shell, SWT.PUSH); + jsOffButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + jsOffButton.setText("JS On"); + jsOffButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(true))); + + + Button loadNextPage = new Button(shell, SWT.PUSH); + loadNextPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + loadNextPage.setText("Load next page"); + loadNextPage.addSelectionListener( SelectionListener.widgetSelectedAdapter(e -> browser.setText(getNewText()))); + + browser.setText(getNewText()); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } + + static String getNewText() { + return "Hello world<br>" + + "<input type=\"button\" value=\"Open Curtain\" onclick=\"return change(this);\" />\n" + + "\n" + + "<script type=\"text/javascript\">\n" + + "function change( el )\n" + + "{\n" + + " if ( el.value === \"Open Curtain\" )\n" + + " el.value = \"Close Curtain\";\n" + + " else\n" + + " el.value = \"Open Curtain\";\n" + + "}\n" + + "</script>" + loadCounter++; + } + + +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528691_StyledTextNull.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528691_StyledTextNull.java new file mode 100644 index 0000000000..be7f7b343b --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug528691_StyledTextNull.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 528691 - [GTK] StyledText ignores text after \u0000 character + * How to run: launch snippet and observe StyledText widget + * Bug description: Only "hello" is displayed + * Expected results: "helloworld" should be displayed + * GTK Version(s): GTK2, GTK3 + */ +public class Bug528691_StyledTextNull { + + public static void main(String[] args) { + final Display display = new Display(); + + final Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + + final StyledText styledText = new StyledText(shell, SWT.BORDER); + styledText.setText("hello\u0000world"); + + shell.setSize(500, 400); + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + display.dispose(); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug529126_TreeMouseDown.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug529126_TreeMouseDown.java new file mode 100644 index 0000000000..328e36753f --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug529126_TreeMouseDown.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.graphics.Region; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.swt.widgets.TreeItem; + +/* + * Title: Bug 529126: [Wayland][GTK3] Tree does not notify SWT.MouseDown listeners + * How to run: launch snippet and click on TreeItems + * Bug description: No output is printed to the console + * Expected results: Output with event info should be printed to the console for each + * mouse down. + * GTK Version(s): GTK3 (Wayland only) + */ +public class Bug529126_TreeMouseDown { + + // Static ================================================================= + + public static void main(String[] args) { + final Display display = new Display(); + final Shell shell = new Shell(display); + shell.setText("Custom gradient selection for Tree"); + shell.setLayout(new FillLayout()); + final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + final int columnCount = 4; + for (int i = 0; i < columnCount; i++) { + final TreeColumn column = new TreeColumn(tree, SWT.NONE); + column.setText("Column " + i); + } + + final int itemCount = 5; + for (int i = 0; i < itemCount; i++) { + final TreeItem item1 = new TreeItem(tree, SWT.NONE); + + for (int j = 0; j < i; j++) { + final TreeItem item2 = new TreeItem(item1, SWT.NONE); + + for (int k = 0; k < j; k++) { + new TreeItem(item2, SWT.NONE); + } + } + } + + tree.addListener(SWT.SetData, event -> { + final TreeItem item = (TreeItem)event.item; + + final TreeItem parentItem = item.getParentItem(); + final String text; + + if (parentItem != null) { + final String parentText = (String)parentItem.getData(); + text = parentText + event.index + "/"; + } + else { + text = "/"; + } + + item.setData(text); + }); + + tree.addListener(SWT.PaintItem, event -> { + final TreeItem item = (TreeItem)event.item; + final String text = (String)item.getData(); + event.gc.drawText(text + " [" + event.index + "]", event.x, event.y, true); + }); + + /* + * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. + * Therefore, it is critical for performance that these methods be + * as efficient as possible. + */ + tree.addListener(SWT.EraseItem, event -> { + event.detail &= ~SWT.HOT; + if ((event.detail & SWT.SELECTED) != 0) { + final GC gc = event.gc; + final Rectangle area = tree.getClientArea(); + /* + * If you wish to paint the selection beyond the end of + * last column, you must change the clipping region. + */ + final int columnCount1 = tree.getColumnCount(); + if (event.index == columnCount1 - 1 || columnCount1 == 0) { + final int width = area.x + area.width - event.x; + if (width > 0) { + final Region region = new Region(); + gc.getClipping(region); + region.add(event.x, event.y, width, event.height); + gc.setClipping(region); + region.dispose(); + } + } + gc.setAdvanced(true); + if (gc.getAdvanced()) { + gc.setAlpha(127); + } + final Rectangle rect = event.getBounds(); + final Color foreground = gc.getForeground(); + final Color background = gc.getBackground(); + gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); + gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + gc.fillGradientRectangle(0, rect.y, 500, rect.height, false); + // restore colors for subsequent drawing + gc.setForeground(foreground); + gc.setBackground(background); + event.detail &= ~SWT.SELECTED; + } + }); + tree.getColumn(0).setWidth(200); + for (int i = 1; i < columnCount; i++) { + tree.getColumn(i).pack(); + } + tree.setSelection(tree.getItem(0)); + + tree.addListener(SWT.MouseDown, event -> System.out.println("event = " + event)); + shell.setSize(500, 500); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug66356_DND_move_reported_to_drag_source_even_though_cancelled.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug66356_DND_move_reported_to_drag_source_even_though_cancelled.java new file mode 100644 index 0000000000..f161d7475c --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug66356_DND_move_reported_to_drag_source_even_though_cancelled.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DragSourceAdapter; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 66356 - DND - move reported to drag source even though cancelled + * How to run: launch snippet, click and drag from the source button back onto it + * Bug description: Move = true is printed + * Expected results: Move = false should be printed if not dragging beyond the source button + * GTK Version(s): 2.x + */ +public class Bug66356_DND_move_reported_to_drag_source_even_though_cancelled { + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + Button source = new Button(shell, SWT.PUSH); + source.setText("Source"); + DragSource dragSource = new DragSource(source, DND.DROP_MOVE); + dragSource.setTransfer(new Transfer[] {TextTransfer.getInstance()}); + dragSource.addDragListener(new DragSourceAdapter() { + @Override + public void dragSetData(DragSourceEvent event) { + event.data = "hello"; + } + @Override + public void dragFinished(DragSourceEvent event) { + System.out.println("Move = "+(event.detail == DND.DROP_MOVE)); + } + }); + Button dest = new Button(shell, SWT.PUSH); + dest.setText("Dest"); + DropTarget dropTarget = new DropTarget(dest, DND.DROP_MOVE); + dropTarget.setTransfer(new Transfer[] {TextTransfer.getInstance()}); +// dropTarget.addDropListener(new DropTargetAdapter() { +// public void drop(DropTargetEvent event) { +// event.detail = DND.DROP_NONE; +// } +// }); +// dropTarget.addDropListener(new DropTargetListener() { +// +// @Override +// public void dropAccept(DropTargetEvent event) { +// // TD Auto-generated method stub +// event.detail = DND.DROP_NONE; +// +// } +// +// @Override +// public void drop(DropTargetEvent event) { +// // TD Auto-generated method stub +// +// } +// +// @Override +// public void dragOver(DropTargetEvent event) { +// // TD Auto-generated method stub +// +// } +// +// @Override +// public void dragOperationChanged(DropTargetEvent event) { +// // TD Auto-generated method stub +// +// } +// +// @Override +// public void dragLeave(DropTargetEvent event) { +// // TD Auto-generated method stub +// +// } +// +// @Override +// public void dragEnter(DropTargetEvent event) { +// // TD Auto-generated method stub +// +// } +// }); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/BugTEMPLATE.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/BugTEMPLATE.java new file mode 100644 index 0000000000..85fd7c9f31 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/BugTEMPLATE.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. All rights reserved. + * The contents of this file are made available under the terms + * of the GNU Lesser General Public License (LGPL) Version 2.1 that + * accompanies this distribution (lgpl-v21.txt). The LGPL is also + * available at http://www.gnu.org/licenses/lgpl.html. If the version + * of the LGPL at http://www.gnu.org is different to the version of + * the LGPL accompanying this distribution and there is any conflict + * between the two license versions, the terms of the LGPL accompanying + * this distribution shall govern. + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: + * How to run: + * Bug description: + * Expected results: + * GTK Version(s): + */ +public class BugTEMPLATE { + + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + shell.setSize(500, 200); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } +} diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/README b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/README new file mode 100644 index 0000000000..30130af85f --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/README @@ -0,0 +1,20 @@ +Place here all snippets that correspond to specific bugs. Naming format is Eclipse Bugzilla number + name, if applicable. + +For example: Bug486334_TableTest.java +Non-bug specific snippets: TreeTest.java + +Please make snippets as clear as possible. At the very least, include a comment above the class definition +that explains how the snippet works, what it does, and what the expected result is. For example: + +/* + * Title: Bug 166720 - [TableEditor] flickers quite a bit when scrolling - Linux GTK + * How to run: launch snippet and scroll TableEditor. + * Bug description: TableEditor flickers when scrolling. + * Expected results: TableEditor should scroll smoothly. + * GTK version(s): GTK2.x + */ + + Alternatively: code instructions into the snippet itself, so that users can simply run the snippet + and visually look at the instructions. + + These snippets can also be used as references in code. For example "// See Gtk test Bug486334_TableTest.java"
\ No newline at end of file |