Bug 528406 - Win32: Toolbar drop down arrow always black
Summary: Win32: Toolbar drop down arrow always black
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC Windows All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on: 508033
Blocks:
  Show dependency tree
 
Reported: 2017-12-11 06:19 EST by Conrad Groth CLA
Modified: 2020-11-23 05:09 EST (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Conrad Groth CLA 2017-12-11 06:19:06 EST
Followup for bug 508033 (see comments 6 and 7):

> Found one issue with the ToolBar's DropDown arrow which continues to be in
> black color irrespective on the foreground/background color. IMO, if
> possible this DropDown triangle should be of the same color as Toolbar
> foreground.

> Unfortunately there's no API method for changing that arrow's Color, so that
> would be more work of custom drawing.
Comment 1 Aaron Lara CLA 2018-07-23 19:41:13 EDT
Guys, has anybody found a solution to this issue yet? Any suggestion on how to create a custom drawer for the Arrow in ToolItems?
Comment 2 Aaron Lara CLA 2018-08-10 16:01:41 EDT
I just addressed this issue in DevStyle by adding a PaintListener to the ToolBar, directly at the end of the contructor and then paint the dopdown arrow for each item like this:


public ToolBar (Composite parent, int style) {
  …
  addPaintListener(new ToolBarPainter());
}

//DropDown icon drawer class
private final class ToolBarPainter implements PaintListener {
    @Override
    public void paintControl(PaintEvent e) {
       if (items == null || items.length == 0) {
           return;
       }
       if (!isDarkTheme) { //Need to check if it’s an eclipse dark theme
         return;
       }
       for (ToolItem item : items) {
         if (item != null && item.isEnabled()) {

           if ((item.getStyle() & SWT.DROP_DOWN) == 0) { 
             continue;
           }


            Rectangle itemBounds = item.getBounds();
					                      
            //Now some maths magic
            Point tbSize = ToolBar.this.getSize();
            int centerY = tbSize.y / 2;
					
            e.gc.setBackground(e.widget.getDisplay()
              .getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
            e.gc.setForeground(e.widget.getDisplay()
              .getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
            
            int[] points = new int[6];
            points[0] = itemBounds.x + itemBounds.width - 14;
            points[1] = centerY - 2;
            points[2] = itemBounds.x + itemBounds.width - 5;
            points[3] = centerY - 2;
            points[4] = itemBounds.x + itemBounds.width - 10;
            points[5] = centerY + 3;
            e.gc.fillPolygon(points);

          }
        }

      }
  }

This fix works well on Windows.
Comment 3 Lars Vogel CLA 2018-09-27 11:45:55 EDT
Aaron, I like the idea. Please convert that idea into a Gerrit for a custom CSS handler so that it can be applied. See http://www.vogella.com/tutorials/Eclipse4CSS/article.html#exercise-define-a-custom-css-selector-and-css-property for an example for a custom CSS handler.
Comment 4 Peter Hermsdorf CLA 2020-03-12 03:21:26 EDT
I had to move the painting some pixels to the right. Under Windows 10 the black arrow which came from the OS was visible for 1 pixel at the right.

So my version is:

final int[] points = new int[6];
points[0] = itemBounds.x + itemBounds.width - 13;
points[1] = centerY - 2;
points[2] = itemBounds.x + itemBounds.width - 3;
points[3] = centerY - 2;
points[4] = itemBounds.x + itemBounds.width - 9;
points[5] = centerY + 3;
e.gc.fillPolygon(points);
Comment 5 Laurent CARON CLA 2020-03-12 04:11:44 EDT
We had the same issue on our RCP-based application. We noticed that on other platform (MacOS, I did not tried on Linux) the color of the arrow is the foreground color of the toolbar.

So in the proposed PaintListener (Comment #2) we should use 

e.gc.setBackground(e.widget.getDisplay()
              .getSystemColor(item.getParent().getForeground());


@Lars : in this case, the "color" property of the CSS entry should change the color of the arrow. What do you think ?
Comment 6 Lars Vogel CLA 2020-05-18 08:11:16 EDT
Alexandr, can you check? I think this one is fixed with your recent changes.
Comment 7 Alexandr Miloslavskiy CLA 2020-05-18 12:33:23 EDT
Our application doesn't use Toolbar, therefore I won't be able to spend time on this issue.

However, I did a quick analysis and found that most likely, on Win10 this code will help when placed in 'createHandle()' :

if (OS.IsAppThemed ())
	OS.SetWindowTheme (handle, "DarkMode\0".toCharArray(), null);
Comment 8 Lars Vogel CLA 2020-06-03 05:42:55 EDT
(In reply to Alexandr Miloslavskiy from comment #7)
> Our application doesn't use Toolbar, therefore I won't be able to spend time
> on this issue.
> 
> However, I did a quick analysis and found that most likely, on Win10 this
> code will help when placed in 'createHandle()' :
> 
> if (OS.IsAppThemed ())
> 	OS.SetWindowTheme (handle, "DarkMode\0".toCharArray(), null);

Thanks, Alexander for this tip. 

Anyone interested in converting this to a Gerrit?
Comment 9 Lakshmi P Shanmugam CLA 2020-07-10 03:12:02 EDT
Resetting target, please re-target as required.
Comment 10 Niraj Modi CLA 2020-09-02 04:52:57 EDT
Mass move out to 4.18
Comment 11 Niraj Modi CLA 2020-11-23 05:09:29 EST
Resetting target.