From 4e1ebbca497571fe4d5f117c7894e1dd71c3115e Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Wed, 16 Dec 2015 16:56:56 -0500 Subject: [PATCH] tmf: Bug 484422: Fix inconsistent vertical zoom In GTK3, after changing the tree font, the tree item bounds are not updated until the tree has been painted. The alignment of tree items should be done after a paint event has occurred. Change-Id: I47617b881d3f0f981bdacf3ddda572c296dffaf7 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/62876 Reviewed-by: Hudson CI Reviewed-by: Francis Giraldeau --- .../ui/widgets/timegraph/TimeGraphCombo.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphCombo.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphCombo.java index 71d42fa368..745d156a42 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphCombo.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphCombo.java @@ -732,7 +732,6 @@ public class TimeGraphCombo extends Composite { fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight()); fTimeGraphViewer.setItemHeight(getItemHeight(tree, true)); alignTreeItems(false); - redraw(); return true; } @@ -748,7 +747,6 @@ public class TimeGraphCombo extends Composite { fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight()); fTimeGraphViewer.setItemHeight(getItemHeight(tree, true)); alignTreeItems(false); - redraw(); } private void sendTimeViewAlignmentChanged() { @@ -1240,6 +1238,31 @@ public class TimeGraphCombo extends Composite { TreeItem item = treeItems.get(topIndex); tree.setTopItem(item); + /* + * In GTK3, the bounds of the tree items are only sure to be correct + * after the tree has been painted. + */ + tree.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + tree.removePaintListener(this); + doAlignTreeItems(); + redraw(); + } + }); + /* Make sure the paint event is triggered. */ + tree.redraw(); + } + + private void doAlignTreeItems() { + Tree tree = fTreeViewer.getTree(); + List treeItems = getVisibleExpandedItems(tree, false); + int topIndex = fTimeGraphViewer.getTopIndex(); + if (topIndex >= treeItems.size()) { + return; + } + TreeItem item = treeItems.get(topIndex); + // get the first filler item so we can calculate the last item's height TreeItem fillerItem = null; for (TreeItem treeItem : fTreeViewer.getTree().getItems()) { @@ -1272,16 +1295,8 @@ public class TimeGraphCombo extends Composite { * newly visible items at the top of the viewer are also aligned. */ fTimeGraphViewer.setTopIndex(topIndex); - item = treeItems.get(topIndex); - tree.setTopItem(item); - while (fTimeGraphViewer.getTopIndex() < topIndex) { - TreeItem nextItem = item; - topIndex--; - item = treeItems.get(topIndex); - tree.setTopItem(item); - bounds = item.getBounds(); - alignTreeItem(item, bounds, nextItem); - fTimeGraphViewer.setTopIndex(topIndex); + if (fTimeGraphViewer.getTopIndex() != topIndex) { + alignTreeItems(false); } } -- 2.34.1