Skip to content

Commit 75c97fd

Browse files
amartya4256HeikoKlare
authored andcommitted
[Win32] Improve StyledText caret scaling on DPI change
This commit replaces the win32-specific caret scaling with API-based resizing to ensure proper repaint on DPI changes. Carets now update location/size via resize() in their DPI change handlers, removing platform dependencies. Additionally, StyledTexts set location, size and visibility of their carets first before calling the DPI change handler of Caret to make sure when Caret is repainted, the size, location and visibility are properly set.
1 parent 440c97a commit 75c97fd

File tree

3 files changed

+5
-31
lines changed

3 files changed

+5
-31
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10912,19 +10912,18 @@ void updateSelection(int startOffset, int replacedLength, int newLength) {
1091210912
* @noreference This method is not intended to be referenced by clients.
1091310913
*/
1091410914
public static void updateAndRefreshCarets(StyledText styledText, Consumer<Caret> caretUpdater) {
10915-
Set<Caret> caretSet = new HashSet<>();
10916-
caretSet.add(styledText.getCaret());
10915+
styledText.updateCaretVisibility();
10916+
styledText.setCaretLocations();
10917+
Set<Caret> caretSet = new LinkedHashSet<>();
1091710918
caretSet.add(styledText.defaultCaret);
10919+
caretSet.add(styledText.getCaret());
1091810920
if (styledText.carets != null) {
1091910921
for (Caret caret : styledText.carets) {
1092010922
caretSet.add(caret);
1092110923
}
1092210924
}
1092310925
caretSet.stream().filter(Objects::nonNull).forEach(caretUpdater);
1092410926

10925-
styledText.updateCaretVisibility();
10926-
styledText.setCaretLocations();
10927-
1092810927
}
1092910928

1093010929
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/CommonWidgetsDPIChangeHandlers.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ private static void handleStyledTextDPIChange(Widget widget, int newZoom, float
5151
if (!(widget instanceof StyledText styledText)) {
5252
return;
5353
}
54-
55-
5654
StyledText.updateAndRefreshCarets(styledText, caretToRefresh -> {
5755
DPIZoomChangeRegistry.applyChange(caretToRefresh, newZoom, scalingFactor);
58-
Caret.win32_setHeight(caretToRefresh, styledText.getLineHeight());
5956
});
6057
}
6158
private static void handleCComboDPIChange(Widget widget, int newZoom, float scalingFactor) {

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -658,29 +658,6 @@ public void setVisible (boolean visible) {
658658
}
659659
}
660660

661-
/**
662-
* <b>IMPORTANT:</b> This method is not part of the public
663-
* API for Image. It is marked public only so that it
664-
* can be shared within the packages provided by SWT. It is not
665-
* available on all platforms, and should never be called from
666-
* application code.
667-
*
668-
* Sets the height o the caret in points.
669-
*
670-
* @param caret the caret to set the height of
671-
* @param height the height of caret to be set in points.
672-
*
673-
* @noreference This method is not intended to be referenced by clients.
674-
*/
675-
public static void win32_setHeight(Caret caret, int height) {
676-
caret.checkWidget();
677-
if(caret.height != height) {
678-
caret.height = height;
679-
caret.resized = true;
680-
}
681-
if(caret.isVisible && caret.hasFocus()) caret.resize();
682-
}
683-
684661
private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) {
685662
if (!(widget instanceof Caret caret)) {
686663
return;
@@ -694,6 +671,7 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
694671
if (caret.font != null) {
695672
caret.setFont(caret.font);
696673
}
674+
if (caret.isVisible && caret.hasFocus ()) caret.resize();
697675
}
698676
}
699677

0 commit comments

Comments
 (0)