@@ -367,6 +367,7 @@ protected void widgetDisposed(Event e) {
367
367
caret .dispose ();
368
368
}
369
369
370
+ @ Override
370
371
public Color getBackground () {
371
372
return backgroundColor != null ? backgroundColor : BACKGROUND_COLOR ;
372
373
}
@@ -390,25 +391,27 @@ public void setForeground(Color color) {
390
391
391
392
private void paintControl (Event e ) {
392
393
Rectangle visibleArea = getVisibleArea ();
393
- e .gc .setFont (getFont ());
394
- e .gc .setForeground (getForeground ());
395
- e .gc .setBackground (getBackground ());
396
- if (!isEnabled ()) {
397
- e .gc .setForeground (DISABLED_COLOR );
398
- }
399
- if (backgroundColor != null ) {
400
- if (!isEnabled () || ((style & SWT .BORDER ) == 1 && !getEditable ())) {
401
- e .gc .setBackground (READONLY_BACKGROUND_COLOR );
394
+ Drawing .drawWithGC (this , e .gc , gc -> {
395
+ gc .setFont (getFont ());
396
+ gc .setForeground (getForeground ());
397
+ gc .setBackground (getBackground ());
398
+ if (!isEnabled ()) {
399
+ gc .setForeground (DISABLED_COLOR );
402
400
}
403
- if ((style & SWT .BORDER ) == 0 && !getEditable ()) {
404
- e .gc .setBackground (getParent ().getBackground ());
401
+ if (backgroundColor != null ) {
402
+ if (!isEnabled () || ((style & SWT .BORDER ) == 1 && !getEditable ())) {
403
+ gc .setBackground (READONLY_BACKGROUND_COLOR );
404
+ }
405
+ if ((style & SWT .BORDER ) == 0 && !getEditable ()) {
406
+ gc .setBackground (getParent ().getBackground ());
407
+ }
405
408
}
406
- }
407
409
408
- drawBackground (e , getClientArea ());
409
- drawText (e , visibleArea );
410
- drawSelection (e , visibleArea );
411
- drawCaret (e , visibleArea );
410
+ drawBackground (gc , getClientArea ());
411
+ drawText (gc , visibleArea );
412
+ drawSelection (gc , visibleArea );
413
+ drawCaret (gc , visibleArea );
414
+ });
412
415
}
413
416
414
417
@ Override
@@ -417,8 +420,7 @@ public void setEnabled(boolean enabled) {
417
420
redraw ();
418
421
}
419
422
420
- private void drawSelection (Event e , Rectangle visibleArea ) {
421
- GC gc = e .gc ;
423
+ private void drawSelection (GC gc , Rectangle visibleArea ) {
422
424
int textLength = model .getText ().length ();
423
425
int start = Math .min (Math .max (model .getSelectionStart (), 0 ), textLength );
424
426
int end = Math .min (Math .max (model .getSelectionEnd (), 0 ), textLength );
@@ -450,53 +452,47 @@ private void drawSelection(Event e, Rectangle visibleArea) {
450
452
}
451
453
}
452
454
453
- private void drawCaret (Event e , Rectangle visibleArea ) {
454
- GC gc = e .gc ;
455
-
455
+ private void drawCaret (GC gc , Rectangle visibleArea ) {
456
456
int caretOffset = model .getCaretOffset ();
457
-
458
457
if (caretOffset >= 0 ) {
459
- Point caretLocation = getLocationByOffset (model .getCaretOffset (), e . gc );
460
- int x = e . x + caretLocation .x - visibleArea .x ;
461
- int y = e . y + caretLocation .y - visibleArea .y ;
458
+ Point caretLocation = getLocationByOffset (model .getCaretOffset (), gc );
459
+ int x = caretLocation .x - visibleArea .x ;
460
+ int y = caretLocation .y - visibleArea .y ;
462
461
getCaret ().setBounds (x , y , 1 , getLineHeight (gc ));
463
462
}
464
463
465
- caret .paint (e );
464
+ caret .paint (gc );
466
465
}
467
466
468
- private void drawText (Event e , Rectangle visibleArea ) {
467
+ private void drawText (GC gc , Rectangle visibleArea ) {
469
468
String [] lines = model .getLines ();
470
469
for (int i = 0 ; i < lines .length ; i ++) {
471
470
String line = lines [i ];
472
- drawTextLine (line , i , e . x , e . y , visibleArea , e . gc );
471
+ drawTextLine (line , i , visibleArea , gc );
473
472
}
474
473
}
475
474
476
475
477
- private void drawTextLine (String text , int lineNumber , int x , int y , Rectangle visibleArea ,
476
+ private void drawTextLine (String text , int lineNumber , Rectangle visibleArea ,
478
477
GC gc ) {
479
478
Point completeTextExtent = gc .textExtent (text );
480
479
Rectangle clientArea = getClientArea ();
481
- int _x ;
480
+ int _x = 0 ;
482
481
if ((style & SWT .CENTER ) != 0 ) {
483
482
_x = (clientArea .width - completeTextExtent .x ) / 2 ;
484
483
} else if ((style & SWT .RIGHT ) != 0 ) {
485
484
_x = clientArea .width - completeTextExtent .x ;
486
- } else { // ((style & SWT.LEFT) != 0)
487
- _x = x ;
488
485
}
489
486
_x -= visibleArea .x ;
490
- int _y = y + lineNumber * completeTextExtent .y - visibleArea .y ;
487
+ int _y = lineNumber * completeTextExtent .y - visibleArea .y ;
491
488
if ((style & SWT .BORDER ) != 0 ) {
492
489
_x += getBorderWidth ();
493
490
_y += getBorderWidth ();
494
491
}
495
492
gc .drawText (text , _x , _y , true );
496
493
}
497
494
498
- private void drawBackground (Event e , Rectangle clientArea ) {
499
- GC gc = e .gc ;
495
+ private void drawBackground (GC gc , Rectangle clientArea ) {
500
496
int height = clientArea .height ;
501
497
final boolean drawLine = (style & SWT .BORDER ) != 0 && getEditable () && isEnabled ();
502
498
if (drawLine ) {
0 commit comments