Skip to content

Commit 1984e06

Browse files
akoch-yattaHeikoKlare
authored andcommitted
[win32] Prevent event on tree column resize
This commit prevents the creation of a SWT.Resize event when tree columns are resized after a zoom change. Therefore, the ignoreColumnResize attribute is added to Tree to copy the behavior of Table in the same scenario. This attribute is used during the resizing because of the zoom change to disable the creation of the resize event. Contributes to #62 and #127
1 parent 4b57615 commit 1984e06

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class Tree extends Composite {
9090
int sortDirection;
9191
boolean dragStarted, gestureCompleted, insertAfter, shrink, ignoreShrink;
9292
boolean ignoreSelect, ignoreExpand, ignoreDeselect, ignoreResize;
93-
boolean lockSelection, oldSelected, newSelected, ignoreColumnMove;
93+
boolean lockSelection, oldSelected, newSelected, ignoreColumnMove, ignoreColumnResize;
9494
boolean linesVisible, customDraw, painted, ignoreItemHeight;
9595
boolean ignoreCustomDraw, ignoreDrawForeground, ignoreDrawBackground, ignoreDrawFocus;
9696
boolean ignoreDrawSelection, ignoreDrawHot, ignoreFullSelection, explorerTheme;
@@ -8090,22 +8090,24 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) {
80908090
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
80918091
OS.RedrawWindow (handle, null, 0, flags);
80928092
}
8093-
TreeColumn column = columns [phdn.iItem];
8094-
if (column != null) {
8095-
column.updateToolTip (phdn.iItem);
8096-
column.sendEvent (SWT.Resize);
8097-
if (isDisposed ()) return LRESULT.ZERO;
8098-
TreeColumn [] newColumns = new TreeColumn [columnCount];
8099-
System.arraycopy (columns, 0, newColumns, 0, columnCount);
8100-
int [] order = getColumnOrder();
8101-
boolean moved = false;
8102-
for (int i=0; i<columnCount; i++) {
8103-
TreeColumn nextColumn = newColumns [order [i]];
8104-
if (moved && !nextColumn.isDisposed ()) {
8105-
nextColumn.updateToolTip (order [i]);
8106-
nextColumn.sendEvent (SWT.Move);
8093+
if (!ignoreColumnResize) {
8094+
TreeColumn column = columns [phdn.iItem];
8095+
if (column != null) {
8096+
column.updateToolTip (phdn.iItem);
8097+
column.sendEvent (SWT.Resize);
8098+
if (isDisposed ()) return LRESULT.ZERO;
8099+
TreeColumn [] newColumns = new TreeColumn [columnCount];
8100+
System.arraycopy (columns, 0, newColumns, 0, columnCount);
8101+
int [] order = getColumnOrder();
8102+
boolean moved = false;
8103+
for (int i=0; i<columnCount; i++) {
8104+
TreeColumn nextColumn = newColumns [order [i]];
8105+
if (moved && !nextColumn.isDisposed ()) {
8106+
nextColumn.updateToolTip (order [i]);
8107+
nextColumn.sendEvent (SWT.Move);
8108+
}
8109+
if (nextColumn == column) moved = true;
81078110
}
8108-
if (nextColumn == column) moved = true;
81098111
}
81108112
}
81118113
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,16 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
764764
if (!(widget instanceof TreeColumn treeColumn)) {
765765
return;
766766
}
767-
treeColumn.setWidth(Math.round(treeColumn.getWidth() * scalingFactor));
767+
Tree tree = treeColumn.getParent();
768+
boolean ignoreColumnResize = tree.ignoreColumnResize;
769+
tree.ignoreColumnResize = true;
770+
final int newColumnWidth = Math.round(treeColumn.getWidthInPixels() * scalingFactor);
771+
treeColumn.setWidthInPixels(newColumnWidth);
772+
tree.ignoreColumnResize = ignoreColumnResize;
773+
768774
Image image = treeColumn.image;
769775
if (image != null) {
770-
treeColumn.setImage (image);
776+
treeColumn.setImage(image);
771777
}
772778
}
773779
}

0 commit comments

Comments
 (0)