Skip to content

Commit

Permalink
[GTK][HiDpi] Code cleanup for removal of non-cairo scale path
Browse files Browse the repository at this point in the history
Fixes #1300
  • Loading branch information
deepika-u committed Jul 10, 2024
1 parent d9fbab8 commit b48f0d1
Show file tree
Hide file tree
Showing 30 changed files with 182 additions and 495 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ public Point getCaretLocation () {
PangoRectangle pos = new PangoRectangle ();
OS.pango_layout_index_to_pos (layout, index, pos);
Point thickness = getThickness (entryHandle);
int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidthInPixels () - thickness.x;
int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidth() - thickness.x;
int y = offset_y [0] + OS.PANGO_PIXELS (pos.y) - thickness.y;
return new Point (x, y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ public void setBounds(int x, int y, int width, int height) {
* Usually called when control is resized or first initialized.
*/
private void setDropDownButtonSize() {
Rectangle rect = getClientAreaInPixels();
Rectangle rect = getClientArea();
int parentWidth = rect.width;
int parentHeight = rect.height;
Point buttonSize = down.computeSize(SWT.DEFAULT, parentHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,8 @@ public boolean getExpanded() {
*/
public int getHeaderHeight () {
checkWidget ();
return DPIUtil.autoScaleDown (getHeaderHeightInPixels ());
}

int getHeaderHeightInPixels() {
checkWidget();

GtkAllocation allocation = new GtkAllocation();
GTK.gtk_widget_get_allocation(GTK.gtk_expander_get_label_widget(handle), allocation);

return allocation.height;
}

Expand All @@ -256,7 +249,7 @@ int getHeaderHeightInPixels() {
*/
public int getHeight() {
checkWidget();
return DPIUtil.autoScaleDown(height);
return height;
}

/**
Expand Down Expand Up @@ -506,11 +499,6 @@ void setForegroundRGBA (GdkRGBA rgba) {
* </ul>
*/
public void setHeight (int height) {
checkWidget ();
setHeightInPixels(DPIUtil.autoScaleUp(height));
}

void setHeightInPixels (int height) {
checkWidget ();
if (height < 0) return;
this.height = height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ long clientHandle () {
}

@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
Point size = super.computeSizeInPixels(wHint, hHint, changed);
public Point computeSize(int wHint, int hHint, boolean changed) {
Point size = super.computeSize(wHint, hHint, changed);
int width = computeNativeSize (handle, SWT.DEFAULT, SWT.DEFAULT, false).x;
size.x = Math.max (size.x, width);
return size;
}
@Override
Rectangle computeTrimInPixels (int x, int y, int width, int height) {
public Rectangle computeTrim(int x, int y, int width, int height) {
checkWidget();
forceResize ();
GtkAllocation allocation = new GtkAllocation();
Expand All @@ -132,8 +132,8 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
}

@Override
Rectangle getClientAreaInPixels () {
Rectangle clientRectangle = super.getClientAreaInPixels ();
public Rectangle getClientArea() {
Rectangle clientRectangle = super.getClientArea();
/*
* Bug 453827 Child position fix.
* SWT's calls to gtk_widget_size_allocate and gtk_widget_set_allocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Point computeNativeSize (long h, int wHint, int hHint, boolean changed) {
}
}
@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget ();
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
Expand Down Expand Up @@ -369,7 +369,7 @@ public int getAlignment () {
}

@Override
int getBorderWidthInPixels () {
public int getBorderWidth() {
checkWidget();
if (frameHandle != 0) {
return getThickness (frameHandle).x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.swt.accessibility.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gtk.*;
import org.eclipse.swt.internal.gtk3.*;
import org.eclipse.swt.internal.gtk4.*;
Expand Down Expand Up @@ -121,7 +120,7 @@ public void addSelectionListener (SelectionListener listener) {
}

@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget ();
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
Expand All @@ -130,19 +129,19 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
//TEMPORARY CODE
if (wHint == 0) {
layout.setWidth (1);
Rectangle rect = DPIUtil.autoScaleUp(layout.getBounds ());
Rectangle rect = layout.getBounds ();
width = 0;
height = rect.height;
} else {
layout.setWidth (DPIUtil.autoScaleDown(wHint));
Rectangle rect = DPIUtil.autoScaleUp(layout.getBounds ());
layout.setWidth(wHint);
Rectangle rect = layout.getBounds ();
width = rect.width;
height = rect.height;
}
layout.setWidth (layoutWidth);
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
int border = getBorderWidthInPixels ();
int border = getBorderWidth();
width += border * 2;
height += border * 2;
return new Point (width, height);
Expand Down Expand Up @@ -191,9 +190,9 @@ void drawWidget(GC gc) {
if ((state & DISABLED) != 0) gc.setForeground (disabledColor);
layout.draw (gc, 0, 0, selStart, selEnd, null, null);
if (hasFocus () && focusIndex != -1) {
Rectangle [] rects = getRectanglesInPixels (focusIndex);
Rectangle [] rects = getRectangles(focusIndex);
for (int i = 0; i < rects.length; i++) {
Rectangle rect = DPIUtil.autoScaleDown(rects [i]);
Rectangle rect = rects [i];
gc.drawFocus (rect.x, rect.y, rect.width, rect.height);
}
}
Expand Down Expand Up @@ -292,7 +291,7 @@ String getNameText () {
return getText ();
}

Rectangle [] getRectanglesInPixels (int linkIndex) {
Rectangle [] getRectangles(int linkIndex) {
int lineCount = layout.getLineCount ();
Rectangle [] rects = new Rectangle [lineCount];
int [] lineOffsets = layout.getLineOffsets ();
Expand All @@ -303,13 +302,13 @@ String getNameText () {
while (point.y > lineOffsets [lineEnd]) lineEnd++;
int index = 0;
if (lineStart == lineEnd) {
rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, point.y));
rects [index++] = layout.getBounds (point.x, point.y);
} else {
rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, lineOffsets [lineStart]-1));
rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (lineOffsets [lineEnd-1], point.y));
rects [index++] = layout.getBounds (point.x, lineOffsets [lineStart]-1);
rects [index++] = layout.getBounds (lineOffsets [lineEnd-1], point.y);
if (lineEnd - lineStart > 1) {
for (int i = lineStart; i < lineEnd - 1; i++) {
rects [index++] = DPIUtil.autoScaleUp (layout.getLineBounds (i));
rects [index++] = layout.getLineBounds (i);
}
}
}
Expand Down Expand Up @@ -365,7 +364,7 @@ long gtk_button_press_event (long widget, long event) {
int x = (int) eventX[0];
int y = (int) eventY[0];
if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
int offset = DPIUtil.autoScaleUp(layout.getOffset (x, y, null));
int offset = layout.getOffset (x, y, null);
int oldSelectionX = selection.x;
int oldSelectionY = selection.y;
selection.x = offset;
Expand All @@ -376,11 +375,11 @@ long gtk_button_press_event (long widget, long event) {
oldSelectionX = oldSelectionY;
oldSelectionY = temp;
}
Rectangle rect = DPIUtil.autoScaleUp(layout.getBounds (oldSelectionX, oldSelectionY));
redrawInPixels (rect.x, rect.y, rect.width, rect.height, false);
Rectangle rect = layout.getBounds (oldSelectionX, oldSelectionY);
redraw(rect.x, rect.y, rect.width, rect.height, false);
}
for (int j = 0; j < offsets.length; j++) {
Rectangle [] rects = getRectanglesInPixels (j);
Rectangle [] rects = getRectangles(j);
for (int i = 0; i < rects.length; i++) {
Rectangle rect = rects [i];
if (rect.contains (x, y)) {
Expand Down Expand Up @@ -419,7 +418,7 @@ long gtk_button_release_event (long widget, long event) {
int x = (int) eventX[0];
int y = (int) eventY[0];
if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
Rectangle [] rects = getRectanglesInPixels (focusIndex);
Rectangle [] rects = getRectangles(focusIndex);
for (int i = 0; i < rects.length; i++) {
Rectangle rect = rects [i];
if (rect.contains (x, y)) {
Expand Down Expand Up @@ -544,7 +543,7 @@ long gtk_motion_notify_event (long widget, long event) {
if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
if ((state[0] & GDK.GDK_BUTTON1_MASK) != 0) {
int oldSelection = selection.y;
selection.y = DPIUtil.autoScaleUp(layout.getOffset (x, y, null));
selection.y = layout.getOffset (x, y, null);
if (selection.y != oldSelection) {
int newSelection = selection.y;
if (oldSelection > newSelection) {
Expand All @@ -553,11 +552,11 @@ long gtk_motion_notify_event (long widget, long event) {
newSelection = temp;
}
Rectangle rect = layout.getBounds (oldSelection, newSelection);
redrawInPixels (rect.x, rect.y, rect.width, rect.height, false);
redraw(rect.x, rect.y, rect.width, rect.height, false);
}
} else {
for (int j = 0; j < offsets.length; j++) {
Rectangle [] rects = getRectanglesInPixels (j);
Rectangle [] rects = getRectangles(j);
for (int i = 0; i < rects.length; i++) {
Rectangle rect = rects [i];
if (rect.contains (x, y)) {
Expand Down Expand Up @@ -810,7 +809,7 @@ int parseMnemonics (char[] buffer, int start, int end, StringBuilder result) {
int setBounds(int x, int y, int width, int height, boolean move, boolean resize) {
int result = super.setBounds (x, y, width,height, move, resize);
if ((result & RESIZED) != 0) {
layout.setWidth (DPIUtil.autoScaleDown((width > 0 ? width : -1)));
layout.setWidth(width > 0 ? width : -1);
redraw ();
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ int applyThemeBackground () {
}

@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget ();
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
Expand All @@ -282,7 +282,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
* based on the number of items in the table
*/
if (size.y == 0 && hHint == SWT.DEFAULT) {
size.y = getItemCount() * getItemHeightInPixels();
size.y = getItemCount() * getItemHeight();
}

/*
Expand All @@ -291,7 +291,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
* so need to assign default height
*/
if (size.y == 0 && hHint == SWT.DEFAULT) size.y = DEFAULT_HEIGHT;
Rectangle trim = computeTrimInPixels (0, 0, size.x, size.y);
Rectangle trim = computeTrim(0, 0, size.x, size.y);
size.x = trim.width;
size.y = trim.height;
return size;
Expand Down Expand Up @@ -543,12 +543,6 @@ public int getItemCount () {
*/
public int getItemHeight () {
checkWidget();
return DPIUtil.autoScaleDown(getItemHeightInPixels());
}

int getItemHeightInPixels() {
checkWidget();

final int BASE_ITEM_PADDING = 1;

int[] h = new int [1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1198,11 +1198,6 @@ public void setEnabled(boolean enabled) {
*/
public void setLocation (int x, int y) {
checkWidget ();
setLocation (new Point (x, y));
}

void setLocationInPixels (int x, int y) {
checkWidget();
if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
this.x = x;
this.y = y;
Expand Down Expand Up @@ -1235,13 +1230,8 @@ void setLocationInPixels (int x, int y) {
*/
public void setLocation (Point location) {
checkWidget ();
setLocationInPixels (DPIUtil.autoScaleUp (location));
}

void setLocationInPixels (Point location) {
checkWidget();
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
setLocationInPixels (location.x, location.y);
setLocation(location.x, location.y);
}

/**
Expand Down
Loading

0 comments on commit b48f0d1

Please sign in to comment.