Skip to content

Commit 730d212

Browse files
Images not aligned properly in Expand Bar
When adding image larger than the header size in expand bar, it was drawn outside of the bar on the top. This was due to wrong calculation and mixing of points and pixels
1 parent e5c589d commit 730d212

File tree

1 file changed

+28
-25
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+28
-25
lines changed

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

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,14 @@ private void drawChevron (long hDC, RECT rect) {
183183

184184
void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
185185
long hDC = gc.handle;
186-
int headerHeight = parent.getBandHeight ();
186+
int headerHeightinPixels = getHeaderHeightInPixels();
187+
int zoom = getZoom();
188+
int imageHeightInPixels = DPIUtil.scaleUp(imageHeight, zoom);
189+
int imageWidthInPixels = DPIUtil.scaleUp(imageWidth, zoom);
190+
187191
RECT rect = new RECT ();
188-
OS.SetRect (rect, x, y, x + width, y + headerHeight);
192+
OS.SetRect (rect, x, y, x + width, y + headerHeightinPixels);
193+
//System.out.println("y = " + y + " Height = " + headerHeightinPixels + " Total = " + (y + headerHeightinPixels));
189194
if (hTheme != 0) {
190195
OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, rect, clipRect);
191196
} else {
@@ -194,14 +199,10 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
194199
OS.SelectObject (hDC, oldBrush);
195200
}
196201
if (image != null) {
197-
int zoom = getZoom();
198202
rect.left += ExpandItem.TEXT_INSET;
199-
if (imageHeight > headerHeight) {
200-
gc.drawImage (image, DPIUtil.scaleDown(rect.left, zoom), DPIUtil.scaleDown(rect.top + headerHeight - imageHeight, zoom));
201-
} else {
202-
gc.drawImage (image, DPIUtil.scaleDown(rect.left, zoom), DPIUtil.scaleDown(rect.top + (headerHeight - imageHeight) / 2, zoom));
203-
}
204-
rect.left += imageWidth;
203+
int yInPoints = DPIUtil.scaleDown(rect.top + ((headerHeightinPixels - imageHeightInPixels) / 2), zoom);
204+
gc.drawImage (image, DPIUtil.scaleDown(rect.left, zoom), yInPoints);
205+
rect.left += imageWidthInPixels;
205206
}
206207
if (text.length () > 0) {
207208
rect.left += ExpandItem.TEXT_INSET;
@@ -213,8 +214,7 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
213214
} else {
214215
buffer = (RLE + text).toCharArray ();
215216
}
216-
}
217-
else {
217+
} else {
218218
buffer = text.toCharArray ();
219219
}
220220
if (hTheme != 0) {
@@ -227,7 +227,7 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
227227
}
228228
int chevronSize = ExpandItem.CHEVRON_SIZE;
229229
rect.left = rect.right - chevronSize;
230-
rect.top = y + (headerHeight - chevronSize) / 2;
230+
rect.top = y;
231231
rect.bottom = rect.top + chevronSize;
232232
if (hTheme != 0) {
233233
int partID = expanded ? OS.EBP_NORMALGROUPCOLLAPSE : OS.EBP_NORMALGROUPEXPAND;
@@ -237,18 +237,18 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
237237
drawChevron (hDC, rect);
238238
}
239239
if (drawFocus) {
240-
OS.SetRect (rect, x + 1, y + 1, x + width - 2, y + headerHeight - 2);
240+
OS.SetRect (rect, x + 1, y + 1, x + width - 2, y + headerHeightinPixels - 2);
241241
OS.DrawFocusRect (hDC, rect);
242242
}
243243
if (expanded) {
244244
if (!parent.isAppThemed ()) {
245245
long pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE));
246246
long oldPen = OS.SelectObject (hDC, pen);
247247
int [] points = {
248-
x, y + headerHeight,
249-
x, y + headerHeight + height,
250-
x + width - 1, y + headerHeight + height,
251-
x + width - 1, y + headerHeight - 1};
248+
x, y + headerHeightinPixels,
249+
x, y + headerHeightinPixels + height,
250+
x + width - 1, y + headerHeightinPixels + height,
251+
x + width - 1, y + headerHeightinPixels - 1};
252252
OS.Polyline (hDC, points, points.length / 2);
253253
OS.SelectObject (hDC, oldPen);
254254
OS.DeleteObject (pen);
@@ -310,7 +310,13 @@ public int getHeaderHeight () {
310310
}
311311

312312
int getHeaderHeightInPixels () {
313-
return Math.max (parent.getBandHeight (), imageHeight);
313+
int headerHeightInPixels = parent.getBandHeight ();
314+
int zoom = getZoom();
315+
int imageHeightInPixels = DPIUtil.scaleUp(imageHeight, zoom);
316+
if(imageHeightInPixels > headerHeightInPixels) {
317+
headerHeightInPixels = imageHeightInPixels + headerHeightInPixels;
318+
}
319+
return headerHeightInPixels;
314320
}
315321

316322
/**
@@ -401,11 +407,8 @@ void releaseWidget () {
401407

402408
void setBoundsInPixels (int x, int y, int width, int height, boolean move, boolean size) {
403409
redraw (true);
404-
int headerHeight = parent.getBandHeight ();
410+
int headerHeightInPixels = getHeaderHeightInPixels();
405411
if (move) {
406-
if (imageHeight > headerHeight) {
407-
y += (imageHeight - headerHeight);
408-
}
409412
this.x = x;
410413
this.y = y;
411414
redraw (true);
@@ -421,8 +424,8 @@ void setBoundsInPixels (int x, int y, int width, int height, boolean move, boole
421424
width = Math.max (0, width - BORDER * 2);
422425
height = Math.max (0, height - BORDER);
423426
}
424-
if (move && size) control.setBoundsInPixels (x, y + headerHeight, width, height);
425-
if (move && !size) control.setLocationInPixels (x, y + headerHeight);
427+
if (move && size) control.setBoundsInPixels (x, y + headerHeightInPixels, width, height);
428+
if (move && !size) control.setLocationInPixels (x, y + headerHeightInPixels);
426429
if (!move && size) control.setSizeInPixels (width, height);
427430
}
428431
}
@@ -504,7 +507,7 @@ public void setImage (Image image) {
504507
super.setImage (image);
505508
int oldImageHeight = imageHeight;
506509
if (image != null) {
507-
Rectangle bounds = image.getBoundsInPixels ();
510+
Rectangle bounds = image.getBounds();
508511
imageHeight = bounds.height;
509512
imageWidth = bounds.width;
510513
} else {

0 commit comments

Comments
 (0)