@@ -43,6 +43,7 @@ public class ExpandItem extends Item {
43
43
boolean expanded , hover ;
44
44
int x , y , width , height ;
45
45
int imageHeight , imageWidth ;
46
+ private static final int IMAGE_MARGIN = 8 ;
46
47
static final int TEXT_INSET = 6 ;
47
48
static final int BORDER = 1 ;
48
49
static final int CHEVRON_SIZE = 24 ;
@@ -183,9 +184,13 @@ private void drawChevron (long hDC, RECT rect) {
183
184
184
185
void drawItem (GC gc , long hTheme , RECT clipRect , boolean drawFocus ) {
185
186
long hDC = gc .handle ;
186
- int headerHeight = parent .getBandHeight ();
187
+ int headerHeightinPixels = getHeaderHeightInPixels ();
188
+ int zoom = getZoom ();
189
+ int imageHeightInPixels = DPIUtil .scaleUp (imageHeight , zoom );
190
+ int imageWidthInPixels = DPIUtil .scaleUp (imageWidth , zoom );
191
+
187
192
RECT rect = new RECT ();
188
- OS .SetRect (rect , x , y , x + width , y + headerHeight );
193
+ OS .SetRect (rect , x , y , x + width , y + headerHeightinPixels );
189
194
if (hTheme != 0 ) {
190
195
OS .DrawThemeBackground (hTheme , hDC , OS .EBP_NORMALGROUPHEAD , 0 , rect , clipRect );
191
196
} else {
@@ -194,14 +199,10 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
194
199
OS .SelectObject (hDC , oldBrush );
195
200
}
196
201
if (image != null ) {
197
- int zoom = getZoom ();
198
202
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 ;
205
206
}
206
207
if (text .length () > 0 ) {
207
208
rect .left += ExpandItem .TEXT_INSET ;
@@ -213,8 +214,7 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
213
214
} else {
214
215
buffer = (RLE + text ).toCharArray ();
215
216
}
216
- }
217
- else {
217
+ } else {
218
218
buffer = text .toCharArray ();
219
219
}
220
220
if (hTheme != 0 ) {
@@ -227,7 +227,7 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
227
227
}
228
228
int chevronSize = ExpandItem .CHEVRON_SIZE ;
229
229
rect .left = rect .right - chevronSize ;
230
- rect .top = y + ( headerHeight - chevronSize ) / 2 ;
230
+ rect .top = y ;
231
231
rect .bottom = rect .top + chevronSize ;
232
232
if (hTheme != 0 ) {
233
233
int partID = expanded ? OS .EBP_NORMALGROUPCOLLAPSE : OS .EBP_NORMALGROUPEXPAND ;
@@ -237,18 +237,18 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
237
237
drawChevron (hDC , rect );
238
238
}
239
239
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 );
241
241
OS .DrawFocusRect (hDC , rect );
242
242
}
243
243
if (expanded ) {
244
244
if (!parent .isAppThemed ()) {
245
245
long pen = OS .CreatePen (OS .PS_SOLID , 1 , OS .GetSysColor (OS .COLOR_BTNFACE ));
246
246
long oldPen = OS .SelectObject (hDC , pen );
247
247
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 };
252
252
OS .Polyline (hDC , points , points .length / 2 );
253
253
OS .SelectObject (hDC , oldPen );
254
254
OS .DeleteObject (pen );
@@ -310,7 +310,13 @@ public int getHeaderHeight () {
310
310
}
311
311
312
312
int getHeaderHeightInPixels () {
313
- return Math .max (parent .getBandHeight (), imageHeight );
313
+ int headerHeightInPixels = parent .getBandHeight ();
314
+ int imageHeightInPixels = DPIUtil .scaleUp (imageHeight , getZoom ());
315
+ int imageHeaderDiff = headerHeightInPixels - imageHeightInPixels ;
316
+ if (imageHeaderDiff < IMAGE_MARGIN ) {
317
+ headerHeightInPixels = imageHeightInPixels + IMAGE_MARGIN ;
318
+ }
319
+ return headerHeightInPixels ;
314
320
}
315
321
316
322
/**
@@ -372,17 +378,20 @@ boolean isHover (int x, int y) {
372
378
373
379
void redraw (boolean all ) {
374
380
long parentHandle = parent .handle ;
375
- int headerHeight = parent .getBandHeight ();
381
+ int headerHeightInPixels = getHeaderHeightInPixels ();
382
+ int zoom = getZoom ();
383
+ int imageHeightInPixels = DPIUtil .scaleUp (imageHeight , zoom );
384
+ int imageWidthInPixels = DPIUtil .scaleUp (imageWidth , zoom );
376
385
RECT rect = new RECT ();
377
- int left = all ? x : x + width - headerHeight ;
378
- OS .SetRect (rect , left , y , x + width , y + headerHeight );
386
+ int left = all ? x : x + width - headerHeightInPixels ;
387
+ OS .SetRect (rect , left , y , x + width , y + headerHeightInPixels );
379
388
OS .InvalidateRect (parentHandle , rect , true );
380
- if (imageHeight > headerHeight ) {
381
- OS .SetRect (rect , x + ExpandItem .TEXT_INSET , y + headerHeight - imageHeight , x + ExpandItem .TEXT_INSET + imageWidth , y );
389
+ if (imageHeightInPixels > headerHeightInPixels ) {
390
+ OS .SetRect (rect , x + ExpandItem .TEXT_INSET , y + headerHeightInPixels - imageHeightInPixels , x + ExpandItem .TEXT_INSET + imageWidthInPixels , y );
382
391
OS .InvalidateRect (parentHandle , rect , true );
383
392
}
384
393
if (!parent .isAppThemed ()) {
385
- OS .SetRect (rect , x , y + headerHeight , x + width , y + headerHeight + height + 1 );
394
+ OS .SetRect (rect , x , y + headerHeightInPixels , x + width , y + headerHeightInPixels + height + 1 );
386
395
OS .InvalidateRect (parentHandle , rect , true );
387
396
}
388
397
}
@@ -401,11 +410,8 @@ void releaseWidget () {
401
410
402
411
void setBoundsInPixels (int x , int y , int width , int height , boolean move , boolean size ) {
403
412
redraw (true );
404
- int headerHeight = parent . getBandHeight ();
413
+ int headerHeightInPixels = getHeaderHeightInPixels ();
405
414
if (move ) {
406
- if (imageHeight > headerHeight ) {
407
- y += (imageHeight - headerHeight );
408
- }
409
415
this .x = x ;
410
416
this .y = y ;
411
417
redraw (true );
@@ -421,8 +427,8 @@ void setBoundsInPixels (int x, int y, int width, int height, boolean move, boole
421
427
width = Math .max (0 , width - BORDER * 2 );
422
428
height = Math .max (0 , height - BORDER );
423
429
}
424
- if (move && size ) control .setBoundsInPixels (x , y + headerHeight , width , height );
425
- if (move && !size ) control .setLocationInPixels (x , y + headerHeight );
430
+ if (move && size ) control .setBoundsInPixels (x , y + headerHeightInPixels , width , height );
431
+ if (move && !size ) control .setLocationInPixels (x , y + headerHeightInPixels );
426
432
if (!move && size ) control .setSizeInPixels (width , height );
427
433
}
428
434
}
@@ -504,7 +510,7 @@ public void setImage (Image image) {
504
510
super .setImage (image );
505
511
int oldImageHeight = imageHeight ;
506
512
if (image != null ) {
507
- Rectangle bounds = image .getBoundsInPixels ();
513
+ Rectangle bounds = image .getBounds ();
508
514
imageHeight = bounds .height ;
509
515
imageWidth = bounds .width ;
510
516
} else {
0 commit comments