@@ -325,27 +325,21 @@ protected void onPaint(PaintEvent e) {
325325 if (bounds .width == 0 || bounds .height == 0 ) {
326326 return ;
327327 }
328+ boolean hasTitleBar = (getExpansionStyle () & TITLE_BAR ) != 0 ;
329+ int theight = 5 ;
330+ int gradientheight = 0 ;
331+ int tvmargin = IGAP ;
328332
329- if ((getExpansionStyle () & TITLE_BAR ) != 0 ) {
333+ bg = (titleColors != null ) ? titleColors .getOrDefault (COLOR_BG , getBackground ()) : getBackground ();
334+ fg = (titleColors != null ) ? getTitleBarForeground () : getForeground ();
335+ border = (titleColors != null ) ? titleColors .getOrDefault (COLOR_BORDER , fg ) : fg ;
336+
337+ if (hasTitleBar ) {
330338 buffer = new Image (getDisplay (), bounds .width , bounds .height );
331339 buffer .setBackground (getBackground ());
332340 gc = new GC (buffer );
333- }
334- if (titleColors != null ) {
335- bg = titleColors .get (COLOR_BG );
336- fg = getTitleBarForeground ();
337- border = titleColors .get (COLOR_BORDER );
338- }
339- if (bg == null )
340- bg = getBackground ();
341- if (fg == null )
342- fg = getForeground ();
343- if (border == null )
344- border = fg ;
345- int theight = 0 ;
346- int gradientheight = 0 ;
347- int tvmargin = IGAP ;
348- if ((getExpansionStyle () & TITLE_BAR ) != 0 ) {
341+
342+ // calculate height
349343 Point tsize = null ;
350344 Point tcsize = null ;
351345 if (toggle != null )
@@ -363,10 +357,8 @@ protected void onPaint(PaintEvent e) {
363357 gradientheight = Math .max (gradientheight , size .y );
364358 theight += tvmargin + tvmargin ;
365359 gradientheight += tvmargin + tvmargin ;
366- } else {
367- theight = 5 ;
368- }
369- if ((getExpansionStyle () & TITLE_BAR ) != 0 ) {
360+
361+ // Background
370362 if (getBackgroundImage () == null )
371363 updateHeaderImage (bg , bounds , gradientheight , theight );
372364 gc .setBackground (getBackground ());
@@ -379,60 +371,71 @@ protected void onPaint(PaintEvent e) {
379371 gc .fillRectangle (bounds .x + bounds .width - marginWidth , 0 ,
380372 marginWidth , theight );
381373 }
382- } else if (isExpanded ()) {
383- gc .setForeground (bg );
384374 gc .setBackground (getBackground ());
385- gc .fillGradientRectangle (marginWidth , marginHeight , bounds .width
386- - marginWidth - marginWidth , theight , true );
387- }
388- gc .setBackground (getBackground ());
389- FormUtil .setAntialias (gc , SWT .ON );
390- // repair the upper left corner
391- gc .fillPolygon (new int [] { marginWidth , marginHeight , marginWidth ,
392- marginHeight + 2 , marginWidth + 2 , marginHeight });
393- // repair the upper right corner
394- gc .fillPolygon (new int [] { bounds .width - marginWidth - 3 ,
395- marginHeight , bounds .width - marginWidth , marginHeight ,
396- bounds .width - marginWidth , marginHeight + 3 });
397- gc .setForeground (border );
398- if (isExpanded () || (getExpansionStyle () & TITLE_BAR ) != 0 ) {
375+ FormUtil .setAntialias (gc , SWT .ON );
376+ // repair the upper left corner
377+ gc .fillPolygon (new int [] { marginWidth , marginHeight , marginWidth ,
378+ marginHeight + 2 , marginWidth + 2 , marginHeight });
379+ // repair the upper right corner
380+ gc .fillPolygon (new int [] { bounds .width - marginWidth - 3 ,
381+ marginHeight , bounds .width - marginWidth , marginHeight ,
382+ bounds .width - marginWidth , marginHeight + 3 });
383+ gc .setForeground (border );
384+
385+ // Draw Lines
399386 // top left curve
400- gc .drawLine (marginWidth , marginHeight + 2 , marginWidth + 2 ,
401- marginHeight );
387+ gc .drawLine (marginWidth , marginHeight + 2 , marginWidth + 2 , marginHeight );
402388 // top edge
403- gc .drawLine (marginWidth + 2 , marginHeight , bounds .width
404- - marginWidth - 3 , marginHeight );
389+ gc .drawLine (marginWidth + 2 , marginHeight , bounds .width - marginWidth - 3 , marginHeight );
405390 // top right curve
406- gc .drawLine (bounds .width - marginWidth - 3 , marginHeight ,
407- bounds .width - marginWidth - 1 , marginHeight + 2 );
408- } else {
409- // collapsed short title bar
410- // top edge
411- gc .drawLine (marginWidth , marginHeight , bounds .width - 1 ,
412- marginHeight );
413- }
414- if ((getExpansionStyle () & TITLE_BAR ) != 0 || isExpanded ()) {
391+ gc .drawLine (bounds .width - marginWidth - 3 , marginHeight , bounds .width - marginWidth - 1 , marginHeight + 2 );
392+
393+ // Expand conditions
415394 // left vertical edge gradient
416395 gc .fillGradientRectangle (marginWidth , marginHeight + 2 , 1 , theight + 2 , true );
417396 // right vertical edge gradient
418397 gc .fillGradientRectangle (bounds .width - marginWidth - 1 , marginHeight + 2 , 1 , theight + 2 , true );
419- }
420- if ((getExpansionStyle () & TITLE_BAR ) != 0 ) {
398+
421399 // New in 3.3 - edge treatment
422400 gc .setForeground (getBackground ());
423401 gc .drawPolyline (new int [] { marginWidth + 1 , marginHeight + gradientheight + 4 , marginWidth + 1 ,
424402 marginHeight + 2 , marginWidth + 2 , marginHeight + 2 , marginWidth + 2 , marginHeight + 1 ,
425403 bounds .width - marginWidth - 3 , marginHeight + 1 , bounds .width - marginWidth - 3 , marginHeight + 2 ,
426404 bounds .width - marginWidth - 2 , marginHeight + 2 , bounds .width - marginWidth - 2 ,
427405 marginHeight + gradientheight + 4 });
406+
407+ } else if (isExpanded ()) {
408+ gc .setForeground (bg );
409+ gc .setBackground (getBackground ());
410+ gc .fillGradientRectangle (marginWidth , marginHeight , bounds .width
411+ - marginWidth - marginWidth , theight , true );
412+ // left vertical edge gradient
413+ gc .fillGradientRectangle (marginWidth , marginHeight + 2 , 1 , theight + 2 , true );
414+ // right vertical edge gradient
415+ gc .fillGradientRectangle (bounds .width - marginWidth - 1 , marginHeight + 2 , 1 , theight + 2 , true );
416+ } else {
417+ gc .setBackground (getBackground ());
418+ FormUtil .setAntialias (gc , SWT .ON );
419+ // repair the upper left corner
420+ gc .fillPolygon (new int [] { marginWidth , marginHeight , marginWidth ,
421+ marginHeight + 2 , marginWidth + 2 , marginHeight });
422+ // repair the upper right corner
423+ gc .fillPolygon (new int [] { bounds .width - marginWidth - 3 ,
424+ marginHeight , bounds .width - marginWidth , marginHeight ,
425+ bounds .width - marginWidth , marginHeight + 3 });
426+ gc .setForeground (border );
427+ // collapsed short title bar
428+ // top edge
429+ gc .drawLine (marginWidth , marginHeight , bounds .width - 1 ,
430+ marginHeight );
428431 }
432+
429433 if (buffer != null ) {
430434 gc .dispose ();
431435 e .gc .drawImage (buffer , 0 , 0 );
432436 buffer .dispose ();
433437 }
434438 }
435-
436439 private void updateHeaderImage (Color bg , Rectangle bounds , int theight , int realtheight ) {
437440 Color gradient = getTitleBarGradientBackground () != null ? getTitleBarGradientBackground () : getBackground ();
438441 Image image = FormImages .getInstance ().getSectionGradientImage (gradient , bg , realtheight ,
0 commit comments