diff options
author | Alexandr Miloslavskiy | 2019-10-21 13:05:07 +0000 |
---|---|---|
committer | Eric Williams | 2019-10-28 13:37:11 +0000 |
commit | 176c61275918a28b2ae7cee3fd080a98b8b4d234 (patch) | |
tree | 18caba5fcbf08fe727ddf088605f97076ca5b47a | |
parent | d73c8c662b22615a3c159d4d9be7c1c1ec217783 (diff) | |
download | eclipse.platform.swt-176c61275918a28b2ae7cee3fd080a98b8b4d234.tar.gz eclipse.platform.swt-176c61275918a28b2ae7cee3fd080a98b8b4d234.tar.xz eclipse.platform.swt-176c61275918a28b2ae7cee3fd080a98b8b4d234.zip |
Bug 552215 - Better test snippets for 541427
Change-Id: I4a71479fece2220ad9114473e6ac6913e630e9bd
Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
2 files changed, 148 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualNativeCTests/BugSnippets/Bug_541427_TreeHeaderNotVisible.cpp b/tests/org.eclipse.swt.tests.gtk/ManualNativeCTests/BugSnippets/Bug_541427_TreeHeaderNotVisible.cpp new file mode 100644 index 0000000000..7b983333c0 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualNativeCTests/BugSnippets/Bug_541427_TreeHeaderNotVisible.cpp @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2019 Syntevo 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: + * Syntevo - initial implementation + *******************************************************************************/ +#include <gtk/gtk.h> +#include <stdio.h> + +int main(int argc, char **argv) { + // boilerplate + gtk_init(&argc, &argv); + GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + g_signal_connect(window, "delete_event", gtk_main_quit, NULL); + gtk_window_resize(GTK_WINDOW(window), 200, 100); + + GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + gtk_container_add(GTK_CONTAINER(window), vbox); + + // create trees + for (int iHeightDiff = -5; iHeightDiff <= 5; iHeightDiff++) { + // frame + char buffer[256]; + sprintf(buffer, "Header %+d px", iHeightDiff); + GtkWidget *frame = gtk_frame_new(buffer); + gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, TRUE, 0); + + // treeview + GtkTreeModel *model = GTK_TREE_MODEL( + gtk_list_store_new(1, G_TYPE_STRING)); + GtkWidget *treeview = gtk_tree_view_new_with_model(model); + g_object_unref(model); + gtk_container_add(GTK_CONTAINER(frame), treeview); + + // some columns. 1 is already enough to demonstrate + for (int iColumn = 0; iColumn < 3; iColumn++) { + gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), + -1, "Column", gtk_cell_renderer_text_new(), "text", iColumn, + NULL); + } + + // resize tree to match header's size + GtkTreeViewColumn *column = gtk_tree_view_get_column( + GTK_TREE_VIEW(treeview), 0); + GtkWidget *columnButton = gtk_tree_view_column_get_button(column); + GtkRequisition columnButtonSize; + gtk_widget_get_preferred_size(columnButton, NULL, &columnButtonSize); + gtk_widget_set_size_request(treeview, 100, + columnButtonSize.height + iHeightDiff); + } + + // boilerplate + gtk_widget_show_all(window); + gtk_main(); + return 0; +} + diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug541427_TreeNoHeader.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug541427_TreeNoHeader.java new file mode 100644 index 0000000000..9b2bf356a2 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug541427_TreeNoHeader.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2018 Matthew Khouzam 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: + * Matthew Khouzam - initial API and implementation + * Syntevo - more tests + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; + +public class Bug541427_TreeNoHeader { + public static void main(String[] args) { + // boilerplate + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new RowLayout(SWT.HORIZONTAL)); + + for (int iTests = 0; iTests < (1 << 2); iTests++) + { + final boolean USE_NO_SCROLL = (iTests & (1 << 0)) != 0; + final boolean PACK_BEFORE_SIZE = (iTests & (1 << 1)) != 0; + + Composite testComposite = new Composite(shell, 0); + testComposite.setLayout(new RowLayout(SWT.VERTICAL)); + + for (int iHeightDiff = -5; iHeightDiff <= 5; iHeightDiff++) + { + Group group = new Group(testComposite, 0); + group.setText(String.format( + "%+d %c%c", + iHeightDiff, + USE_NO_SCROLL ? 'N' : '_', + PACK_BEFORE_SIZE ? 'P' : '_' + )); + + final Tree tree = new Tree(group, USE_NO_SCROLL ? SWT.NO_SCROLL : 0); + tree.setHeaderVisible(true); + + // Remember header height before creating columns. + // It returns 0 after a column is created, is that another bug? + int treeH = tree.getHeaderHeight() + iHeightDiff; + + // some columns. 1 is already enough to demonstrate + for (int iColumn = 0; iColumn < 3; iColumn++) + { + TreeColumn column = new TreeColumn(tree, SWT.NONE); + column.setText("Column"); + column.setWidth(70); + } + + if (PACK_BEFORE_SIZE) + tree.pack(); + + tree.setBounds(0, 0, 220, treeH); + } + } + + // boilerplate + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } +}
\ No newline at end of file |