Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.swt.cocoa.macosx.aarch64" version="2">
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java" type="org.eclipse.swt.graphics.GC">
<filter comment="Bogus problem" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.graphics.GC"/>
<message_argument value="handle"/>
</message_arguments>
</filter>
</resource>
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java" type="org.eclipse.swt.widgets.Composite">
<filter id="576778288">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.swt.cocoa.macosx.x86_64" version="2">
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java" type="org.eclipse.swt.graphics.GC">
<filter comment="Bogus problem" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.graphics.GC"/>
<message_argument value="handle"/>
</message_arguments>
</filter>
</resource>
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java" type="org.eclipse.swt.widgets.Composite">
<filter id="576778288">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.swt.gtk.linux.aarch64" version="2">
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java" type="org.eclipse.swt.graphics.GC">
<filter comment="Bogus problem" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.graphics.GC"/>
<message_argument value="handle"/>
</message_arguments>
</filter>
</resource>
<resource path="Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java" type="org.eclipse.swt.widgets.Composite">
<filter id="576778288">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.swt.gtk.linux.loongarch64" version="2">
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java" type="org.eclipse.swt.graphics.GC">
<filter comment="Bogus problem" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.graphics.GC"/>
<message_argument value="handle"/>
</message_arguments>
</filter>
</resource>
<resource path="Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java" type="org.eclipse.swt.widgets.Composite">
<filter id="576778288">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.swt.gtk.linux.ppc64le" version="2">
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java" type="org.eclipse.swt.graphics.GC">
<filter comment="Bogus problem" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.graphics.GC"/>
<message_argument value="handle"/>
</message_arguments>
</filter>
</resource>
<resource path="Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java" type="org.eclipse.swt.widgets.Composite">
<filter id="576778288">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.swt.gtk.linux.riscv64" version="2">
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java" type="org.eclipse.swt.graphics.GC">
<filter comment="Bogus problem" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.graphics.GC"/>
<message_argument value="handle"/>
</message_arguments>
</filter>
</resource>
<resource path="Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java" type="org.eclipse.swt.widgets.Composite">
<filter id="576778288">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.swt.gtk.linux.x86_64" version="2">
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java" type="org.eclipse.swt.graphics.GC">
<filter comment="Bogus problem" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.graphics.GC"/>
<message_argument value="handle"/>
</message_arguments>
</filter>
</resource>
<resource path="Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java" type="org.eclipse.swt.widgets.Composite">
<filter id="576778288">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.swt.win32.win32.aarch64" version="2">
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java" type="org.eclipse.swt.graphics.GC">
<filter comment="Bogus problem" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.graphics.GC"/>
<message_argument value="handle"/>
</message_arguments>
</filter>
</resource>
<resource path="Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleAutomation.java" type="org.eclipse.swt.ole.win32.OleAutomation">
<filter id="338944126">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.swt.win32.win32.x86_64" version="2">
<resource path="Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java" type="org.eclipse.swt.graphics.GC">
<filter comment="Bogus problem" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.graphics.GC"/>
<message_argument value="handle"/>
</message_arguments>
</filter>
</resource>
<resource path="Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleAutomation.java" type="org.eclipse.swt.ole.win32.OleAutomation">
<filter id="338944126">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ public synchronized void start() {
final Runnable [] timer = new Runnable [1];
timer [0] = () -> {
if (!active) return;
GC gc = new GC(AnimatedProgress.this);
paintStripes(gc);
gc.dispose();
try (var gc = GC.create(AnimatedProgress.this)) {
paintStripes(gc);
}
display.timerExec (SLEEP, timer [0]);
};
display.timerExec (SLEEP, timer [0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,17 @@ private Point getTotalSize(Image image, String text) {
size.y += r.height;
}

GC gc = new GC(this);
if (text != null && text.length() > 0) {
Point e = gc.textExtent(text, DRAW_FLAGS);
size.x += e.x;
size.y = Math.max(size.y, e.y);
if (image != null) size.x += GAP;
} else {
size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
try (var gc = GC.create(this)) {
if (text != null && text.length() > 0) {
Point e = gc.textExtent(text, DRAW_FLAGS);
size.x += e.x;
size.y = Math.max(size.y, e.y);
if (image != null)
size.x += GAP;
} else {
size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
}
}
gc.dispose();

return size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3835,93 +3835,94 @@ boolean updateItems() {
}

boolean updateItems (int showIndex) {
GC gc = new GC(this);
if (!single && !mru && showIndex != -1) {
// make sure selected item will be showing
int firstIndex = showIndex;
if (priority[0] < showIndex) {
int maxWidth = getRightItemEdge(gc) - getLeftItemEdge(gc, CTabFolderRenderer.PART_BORDER);
int width = 0;
int[] widths = new int[items.length];
for (int i = priority[0]; i <= showIndex; i++) {
int state = CTabFolderRenderer.MINIMUM_SIZE;
if (i == selectedIndex) state |= SWT.SELECTED;
widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x;
width += widths[i];
if (width > maxWidth) break;
}
if (width > maxWidth) {
width = 0;
for (int i = showIndex; i >= 0; i--) {
int state = CTabFolderRenderer.MINIMUM_SIZE;
if (i == selectedIndex) state |= SWT.SELECTED;
if (widths[i] == 0) widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x;
width += widths[i];
if (width > maxWidth) break;
firstIndex = i;
}
} else {
firstIndex = priority[0];
for (int i = showIndex + 1; i < items.length; i++) {
boolean changed = false;
try(var gc = GC.create(this)) {
if (!single && !mru && showIndex != -1) {
// make sure selected item will be showing
int firstIndex = showIndex;
if (priority[0] < showIndex) {
int maxWidth = getRightItemEdge(gc) - getLeftItemEdge(gc, CTabFolderRenderer.PART_BORDER);
int width = 0;
int[] widths = new int[items.length];
for (int i = priority[0]; i <= showIndex; i++) {
int state = CTabFolderRenderer.MINIMUM_SIZE;
if (i == selectedIndex) state |= SWT.SELECTED;
widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x;
width += widths[i];
if (width >= maxWidth) break;
if (width > maxWidth) break;
}
if (width < maxWidth) {
for (int i = priority[0] - 1; i >= 0; i--) {
if (width > maxWidth) {
width = 0;
for (int i = showIndex; i >= 0; i--) {
int state = CTabFolderRenderer.MINIMUM_SIZE;
if (i == selectedIndex) state |= SWT.SELECTED;
if (widths[i] == 0) widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x;
width += widths[i];
if (width > maxWidth) break;
firstIndex = i;
}
} else {
firstIndex = priority[0];
for (int i = showIndex + 1; i < items.length; i++) {
int state = CTabFolderRenderer.MINIMUM_SIZE;
if (i == selectedIndex) state |= SWT.SELECTED;
widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x;
width += widths[i];
if (width >= maxWidth) break;
}
if (width < maxWidth) {
for (int i = priority[0] - 1; i >= 0; i--) {
int state = CTabFolderRenderer.MINIMUM_SIZE;
if (i == selectedIndex) state |= SWT.SELECTED;
if (widths[i] == 0) widths[i] = renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x;
width += widths[i];
if (width > maxWidth) break;
firstIndex = i;
}
}
}
}

}
if (firstIndex != priority[0]) {
int index = 0;
// enumerate tabs from first visible to the last existing one (sorted ascending)
for (int i = firstIndex; i < items.length; i++) {
priority[index++] = i;
}
// enumerate hidden tabs on the left hand from first visible one
// in the inverse order (sorted descending) so that the originally
// first opened tab is always at the end of the list
for (int i = firstIndex - 1; i >= 0; i--) {
priority[index++] = i;
if (firstIndex != priority[0]) {
int index = 0;
// enumerate tabs from first visible to the last existing one (sorted ascending)
for (int i = firstIndex; i < items.length; i++) {
priority[index++] = i;
}
// enumerate hidden tabs on the left hand from first visible one
// in the inverse order (sorted descending) so that the originally
// first opened tab is always at the end of the list
for (int i = firstIndex - 1; i >= 0; i--) {
priority[index++] = i;
}
}
}
}

boolean oldShowChevron = showChevron;
boolean changed = setItemSize(gc);
updateButtons();
boolean chevronChanged = showChevron != oldShowChevron;
if (chevronChanged) {
if (updateTabHeight(false)) {
// Tab height has changed. Item sizes have to be set again.
changed |= setItemSize(gc);
boolean oldShowChevron = showChevron;
changed = setItemSize(gc);
updateButtons();
boolean chevronChanged = showChevron != oldShowChevron;
if (chevronChanged) {
if (updateTabHeight(false)) {
// Tab height has changed. Item sizes have to be set again.
changed |= setItemSize(gc);
}
}
changed |= setItemLocation(gc);
setButtonBounds();
changed |= chevronChanged;
if (changed && getToolTipText() != null) {
Point pt = toControl(getDisplay().getCursorLocation());
_setToolTipText(pt.x, pt.y);
}
}
changed |= setItemLocation(gc);
setButtonBounds();
changed |= chevronChanged;
if (changed && getToolTipText() != null) {
Point pt = toControl(getDisplay().getCursorLocation());
_setToolTipText(pt.x, pt.y);
}
gc.dispose();
return changed;
}
boolean updateTabHeight(boolean force){
int oldHeight = tabHeight;
GC gc = new GC(this);
tabHeight = renderer.computeSize(CTabFolderRenderer.PART_HEADER, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).y;
gc.dispose();
try(var gc = GC.create(this)) {
tabHeight = renderer.computeSize(CTabFolderRenderer.PART_HEADER, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).y;
}
if (fixedTabHeight == SWT.DEFAULT && controls != null && controls.length > 0) {
for (int i = 0; i < controls.length; i++) {
if ((controlAlignments[i] & SWT.WRAP) == 0 && !controls[i].isDisposed() && controls[i].getVisible()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1500,10 +1500,10 @@ void setFont(Font font, int tabs) {
tabWidth = layout.getBounds().width;
layout.dispose();
if (styledText != null) {
GC gc = new GC(styledText);
averageCharWidth = (int) gc.getFontMetrics().getAverageCharacterWidth();
fixedPitch = gc.stringExtent("l").x == gc.stringExtent("W").x; //$NON-NLS-1$ //$NON-NLS-2$
gc.dispose();
try (var gc = GC.create(styledText)) {
averageCharWidth = (int) gc.getFontMetrics().getAverageCharacterWidth();
fixedPitch = gc.stringExtent("l").x == gc.stringExtent("W").x; //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
void setLineAlignment(int startLine, int count, int alignment) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.eclipse.swt.graphics;

/**
* An AutoCloseable implementation of GC which calls dispose in the close
* method. Can be created via {@link GC#create(Drawable)}.
*
* @since 3.133
*/
public final class AutoDisposableGC extends GC implements AutoCloseable {

AutoDisposableGC(Drawable drawable, int style) {
super(drawable, style);
}
@Override
public void close() {
dispose();
}
}
Loading
Loading