Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 293230

Summary: Support SWT.ICON_SEARCH and SWT.ICON_CANCEL for native find/filter/search box for Windows 7 / Windows 10
Product: [Eclipse Project] Platform Reporter: Mik Kersten <mik.kersten>
Component: SWTAssignee: Nikita Nemkin <nikita>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: alexandr.miloslavskiy, annafed, a_zimmermann, bokowski, daniel_megert, deepakazad, eclipse.felipe, gunnar, info, jan.krakora.cz, julian.ruppel, ladoe00, Lars.Vogel, lshanmug, lukasz.milewski, markus.kell.r, Mike_Wilson, mseele, nikita, niraj.modi, peter.hermsdorf, prakash, psuzzi, remy.suen, rico.scholz, ruediger.herrmann, shawn.minto, Silenio_Quarti, simon.scholz, susan, tom.schindl
Version: 3.6Keywords: helpwanted
Target Milestone: 4.13 M1   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/139609
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=c4446b5e7d895c1bbe3231a1b6440910c7c14932
https://git.eclipse.org/r/143789
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=6434e727aafcb8d724a9bab0c65f18e15e6b596b
https://git.eclipse.org/r/143813
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=bf374552cac5b50f6b86727909611fb3d0aafce9
https://git.eclipse.org/r/143924
https://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=50ee0c383a18440368898c550655bc484faeb85e
https://git.eclipse.org/r/145850
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=f33ceb16360059667b53e20980126e7a060fd520
https://bugs.eclipse.org/bugs/show_bug.cgi?id=558652
Whiteboard:
Bug Depends on: 302747, 548171    
Bug Blocks: 293226, 315772, 321418, 325565, 548169, 548798, 552822    
Attachments:
Description Flags
search box in MSIE
none
find icon
none
starting patch
none
hack patch for Text none

Description Mik Kersten CLA 2009-10-23 19:42:55 EDT
Windows 7 applications use a common find/filter/search box style (see first attachment).  Eclipse already integrates its FilteredTree text box look with the native Mac OS widget.  The idea here is to do the same thing for Windows 7.
Comment 1 Mik Kersten CLA 2009-10-23 19:59:03 EDT
Created attachment 150430 [details]
search box in MSIE
Comment 2 Shawn Minto CLA 2010-01-29 17:00:32 EST
After some further investigation of this, it looks like the search box in IE and Windows Explorer are not a native widget so I am moving this bug to Platform UI.  To get a native look and feel, we plan to emulate the behavior to be the same/similar to how the search box in Windows Explorer works (i.e. magnifying glass icon to show that it is a search box which turns into the clear button when the search is performed and a drop-down that has some previous search results and potentially other search actions).  We will start by doing this on the Mylyn Task List and then work on pushing the changes up to the FilteredTree implementation so that all Eclipse filtered trees have this support.

If anyone has any feedback on this approach, please let us know.
Comment 3 Felipe Heidrich CLA 2010-02-01 12:32:04 EST
You are right, there is no native control (in win32) that is what you want.
See http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/a07c453a-c5dd-40ed-8895-6615cc808d91/
This is also a good link http://msdn.microsoft.com/en-us/library/aa511489.aspx

You should probably start with something like this:
int flags = SWT.SEARCH | SWT.ICON_SEARCH | SWTICON_CANCEL;
Text text = Text(parent, flags);
int style = text.getStyle();
if ((flags & style) == flags) {
 //all hints were honoured by the OS
} else {
 if ((SWT.ICON_SEARCH & style) == 0) {
   //OS doesn't support ICON_SEARCH, enable draw/emulate code for search
 }
 if ((SWT.ICON_CANCEL & style) == 0) {
   //OS doesn't support ICON_CANCEL, enable draw/emulate code for search
 }
}


You can emulate the icons by drawing over the contorl + hitting test, harder to implement, looks nicer. Or by placing button to the left and right of it (easy to implement).

Before starting to code, I'd check if nebula already offers a control like that.
Comment 4 Mik Kersten CLA 2010-02-01 18:45:53 EST
Created attachment 157852 [details]
find icon

Shawn: Here is a find/search icon I made a while back, based on the Eclipse icon set, which you can use for the time being.  Hopefully Microsoft can provide us with a way of accessing that blue Search icon that's used by IE and Windows Explorer.
Comment 5 Shawn Minto CLA 2010-02-11 19:31:12 EST
Created attachment 158941 [details]
starting patch

Attached is a patch that creates a new class to encapsulate the mix of emulated and native search controls. As there is no native control for this, I started by taking the implementation that was used by FilteredTree (which is an emulation) and extracting it to a different control and having FilteredTree use this implementation.  I can extend this further to support a mix of native and emulated widgets if there is a need for it.

Other parts of Eclipse are starting to copy this implementation from FilteredTree for use in other ways (i.e. Mylyn/P2 discovery searches), therefore making it beneficial to create a standard look and feel so all "Find" boxes in Eclipse have the same behavior.  This also means that when a platform gets native support for the search field, then all search boxes will get the new behavior.

I am still investigating if there is a way to get a more native looking icon on Windows from the system, but for now, I am using the image that was attached by Mik.  Also, I am looking at extending this control to have support for search history that can be managed by the view/control that is using this.  With this, we could provide a place where integrators could add in links to help users search (i.e. a resource navigator could link to the search dialog).
Comment 6 Boris Bokowski CLA 2010-02-12 11:38:19 EST
Realistically, the Platform UI team won't have the cycles to sheperd this "starting patch" into 3.6 in time for the API freeze (which is in four weeks). Everybody is busy with e4, EclipseCon, and their existing 3.6 commitments. Let's target this for 3.7. Sorry!
Comment 7 Thomas Schindl CLA 2010-02-17 01:01:31 EST
I can offer you to add the widget to nebula if you want to. It would live there as it's own control, in it's own bundle, ... .
Comment 8 Mik Kersten CLA 2010-02-17 13:47:05 EST
(In reply to comment #7)
> I can offer you to add the widget to nebula if you want to. It would live there
> as it's own control, in it's own bundle, ... .

Thanks for the offer Tom.  One of our key goals at this point is that the search/find widget that shows in the default perspective of several EPP distributions, the "Find" box on top of the Task List, takes on the modern look.  So I think that we're best off putting this into Mylyn Commons UI for now, where we have other UI widgets such as the desktop notification popups.  But I'd be happy to chat about combining what we're doing in Mylyn Commons UI with Nebula, since there is some overlap.

Shawn: Please let Boris know of how you're approaching adding this functionality in case he has any ideas.
Comment 9 Shawn Minto CLA 2010-02-17 19:05:46 EST
Boris, 

My current approach to implementing this would be to create a TextSearchControl that extends Composite and supports the idea of automatic (current filtered tree implementation) or user-triggered find (user has to hit enter).  This composite would use similar code to what the filtered tree does to check if the native control can be used, or if it should be emulated.  The basics of the emulation would be the same as filtered tree using labels and a composite with a border.  The client of this control could then register selection listeners on it so they can be notified of widgetDefaultSelected when the find/clear icon was pressed.  For the emulated control, these events would be mocked-up to look like the events from the native controls so its behavior to the client would be seamless.  

To improve this widget, I am planning on adding some history support for the find box and the ability that clients can create additional controls in this history popup to perform more advanced searches (i.e. a file navigator could have a button to open the search page with the search field filled out with the filter text).

Any thoughts on the approach that I am taking for this widget would be greatly appreciated.

I have created a Mylyn bug for this (bug 303138) so that we can track the progress of the implementation of the current feature.
Comment 10 Boris Bokowski CLA 2010-02-17 22:37:40 EST
(In reply to comment #9)
> Any thoughts on the approach that I am taking for this widget would be greatly
> appreciated.

Sounds good to me. Felipe, any comments from an SWT viewpoint?
Comment 11 Felipe Heidrich CLA 2010-02-18 09:59:59 EST
(In reply to comment #10)
> (In reply to comment #9)
> > Any thoughts on the approach that I am taking for this widget would be greatly
> > appreciated.
> Sounds good to me. Felipe, any comments from an SWT viewpoint?

GTK, Carbon and Cocoa already implement the hints SWT.ICON_CANCEL and SWT.ICON_SEARCH. Maybe win32 should implement them too.
We know that win32 does not have native support for it, but we could emulate in our win32 code (like IE does: one Edit control with one toolbar in each side).
Comment 12 Shawn Minto CLA 2010-02-18 12:07:20 EST
(In reply to comment #11)
> (In reply to comment #10)
> > (In reply to comment #9)
> > > Any thoughts on the approach that I am taking for this widget would be
> greatly
> > > appreciated.
> > Sounds good to me. Felipe, any comments from an SWT viewpoint?
> 
> GTK, Carbon and Cocoa already implement the hints SWT.ICON_CANCEL and
> SWT.ICON_SEARCH. Maybe win32 should implement them too.
> We know that win32 does not have native support for it, but we could emulate in
> our win32 code (like IE does: one Edit control with one toolbar in each side).

This could work as well and I could look at creating a patch for this if it has a chance of making 3.6.  I would prefer to do it more like how Explorer does it with a toolbar on the right side only that either switches the clear and find icons (so that users know that it is a search field), or show both when there is text in the control.  Are there any examples in SWT where this type of emulation is done already instead of using just the native control?
Comment 13 Susan McCourt CLA 2010-02-18 13:40:26 EST
(In reply to comment #12)
> (In reply to comment #11)
> > (In reply to comment #10)
> > > (In reply to comment #9)
> > > > Any thoughts on the approach that I am taking for this widget would be
> > greatly
> > > > appreciated.
> > > Sounds good to me. Felipe, any comments from an SWT viewpoint?
> > 
> > GTK, Carbon and Cocoa already implement the hints SWT.ICON_CANCEL and
> > SWT.ICON_SEARCH. Maybe win32 should implement them too.
> > We know that win32 does not have native support for it, but we could emulate in
> > our win32 code (like IE does: one Edit control with one toolbar in each side).
> 
> This could work as well and I could look at creating a patch for this if it has
> a chance of making 3.6.  I would prefer to do it more like how Explorer does it
> with a toolbar on the right side only that either switches the clear and find
> icons (so that users know that it is a search field), or show both when there
> is text in the control.  Are there any examples in SWT where this type of
> emulation is done already instead of using just the native control?

If this approach is taken, then there is no new API required on the platform side, right?  It's "just" ;-) a matter of implementing the behavior in an emulated way on Windows.  I'd love to see this happen for 3.6, and FilteredTree could be updated to use it.

Then, early in 3.7, we could expose the box as API separate from FilteredTree and start fixing up the other use cases where it's needed.
Comment 14 Silenio Quarti CLA 2010-02-19 09:58:59 EST
Created attachment 159558 [details]
hack patch for Text

This is a hack that shows how to emulate the search field by adding a toolbar. 
It is a good start, but there are lots of rough edges to work on (computeSize(), events, etc). The toolbar buttons look quite ugly, maybe it would be better to use static labels instead. The edit border should probably be around the whole widget as well. It uses predefined images in the OS, but they do not look that great either.

public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display);

	Text text = new Text(shell, SWT.SEARCH | SWT.BORDER);
	text.setText("Hello");
	text.setBounds(10, 10, 300, 22);
	shell.setSize(400, 300);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
Comment 15 Eric Moffatt CLA 2010-04-27 15:41:20 EDT
Since most of the input has been coming from the SWT team I'm passing this on to them. Feel free to punt this back if you think it's the wrong place...
Comment 16 Dani Megert CLA 2010-07-07 03:08:29 EDT
Best approach for clients would be to get rid of the "hint" flag on
org.eclipse.swt.SWT.ICON_CANCEL and org.eclipse.swt.ICON_SEARCH and support this on all platforms.
Comment 17 Lars Vogel CLA 2013-02-06 11:07:48 EST
*** Bug 400070 has been marked as a duplicate of this bug. ***
Comment 18 Eric CLA 2013-12-18 09:03:13 EST
Any news on this?  Do we have a widget in Nebula or somewhere else?  I see a few applications built on top of Eclipse showing a search text box with a magnifier button and I'd like to have the same in mine.  Are those all running "proprietary" widgets?
Comment 19 Lars Vogel CLA 2018-04-27 11:14:38 EDT
If I understand this long discussion correctly, it is about support the SWT.ICON_CANCEL, SWT.ICON_SEARCH hints also in win32 SWT.

Quote:
----
GTK, Carbon and Cocoa already implement the hints SWT.ICON_CANCEL and SWT.ICON_SEARCH. Maybe win32 should implement them too.
-----

We have a few hacks in platform UI in which we emulate these icons if we are on Windows. Would be nice to have this directly handled by SWT
Comment 20 Dani Megert CLA 2018-04-27 12:44:50 EDT
(In reply to Lars Vogel from comment #19)
> If I understand this long discussion correctly, it is about support the
> SWT.ICON_CANCEL, SWT.ICON_SEARCH hints also in win32 SWT.
> 
> Quote:
> ----
> GTK, Carbon and Cocoa already implement the hints SWT.ICON_CANCEL and
> SWT.ICON_SEARCH. Maybe win32 should implement them too.
> -----
> 
> We have a few hacks in platform UI in which we emulate these icons if we are
> on Windows. Would be nice to have this directly handled by SWT

Best to see the workarounds is in FilteredTree.
Comment 21 Eclipse Genie CLA 2019-03-27 11:23:56 EDT
New Gerrit change created: https://git.eclipse.org/r/139609
Comment 23 Lars Vogel CLA 2019-06-11 14:58:28 EDT
Thanks Nikita. Can you please add this new functionality to the N&N for 4.13?
Comment 24 Niraj Modi CLA 2019-06-12 00:33:56 EDT
(In reply to Eclipse Genie from comment #22)
> Gerrit change https://git.eclipse.org/r/139609 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=c4446b5e7d895c1bbe3231a1b6440910c7c14932

Reopening.
Above patch caused native build input to fail on build machine whereas the native build is working fine locally.

Issue reported via bug 548171:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=548171#c1
Comment 25 Niraj Modi CLA 2019-06-12 00:34:39 EDT
(In reply to Eclipse Genie from comment #22)
> Gerrit change https://git.eclipse.org/r/139609 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=c4446b5e7d895c1bbe3231a1b6440910c7c14932

Reverting above patch for now.
Comment 26 Eclipse Genie CLA 2019-06-12 00:36:06 EDT
New Gerrit change created: https://git.eclipse.org/r/143789
Comment 28 Niraj Modi CLA 2019-06-12 01:30:12 EDT
Hi Nikita,
Changes introduced in line 55 of swt.rc w.r.t. search.ico is causing the native build to fail on Windows build machine, exact error looks like below:
swt.rc(55) : error RC2176 : old DIB in search.ico; pass it through SDKPAINT

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x64\rc.EXE"' : return code '0x1'
Stop.
Comment 29 Niraj Modi CLA 2019-06-12 01:45:09 EDT
(In reply to Niraj Modi from comment #28)
> Hi Nikita,
> Changes introduced in line 55 of swt.rc w.r.t. search.ico is causing the
> native build to fail on Windows build machine, exact error looks like below:
> swt.rc(55) : error RC2176 : old DIB in search.ico; pass it through SDKPAINT
> 
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Windows
> Kits\10\bin\10.0.16299.0\x64\rc.EXE"' : return code '0x1'
> Stop.

With my investigation on this issue it seems the search.ico file has an old format DIB(Device Independent Bitmap), and should be converted to the current format.

IMO, as suggested in the error message: "pass it through SDKPAINT", we should open these both search.ico and cancel.ico files with SDKPAINT application to fix the DIB format.
Comment 30 Niraj Modi CLA 2019-06-12 01:49:49 EDT
More specific details on the error as listed on Microsoft docs:
https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/resource-compiler-error-rw2003?view=vs-2019

Error: Old DIB in resource-name. Pass it through SDKPAINT

A Device Independent Bitmap (DIB) in the specified resource is not compatible with the Windows 3.0 format. The bitmap must be redrawn or converted to the 3.x format.
Comment 31 Nikita Nemkin CLA 2019-06-12 04:25:13 EDT
(In reply to Niraj Modi from comment #28)
> Hi Nikita,
> Changes introduced in line 55 of swt.rc w.r.t. search.ico is causing the
> native build to fail on Windows build machine, exact error looks like below:
> swt.rc(55) : error RC2176 : old DIB in search.ico; pass it through SDKPAINT
> 
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Windows
> Kits\10\bin\10.0.16299.0\x64\rc.EXE"' : return code '0x1'
> Stop.

RC2176 is a generic error that means "can't parse the icon". SDKPAINT is unrelated Win 2.0 era stuff.

The problem is with the Jenkins job. It uses "unzip -aa" command (see https://ci.eclipse.org/releng/job/win32_x86_64/lastFailedBuild/console) to extract native SWT sources. "-aa" flag forces unzip to treat all files as text and causes corruption in binary files like icons.

The original reason for using the "-aa" flag is probably to ensure Windows line endings in the build.bat file.

The correct solution for this is to use .gitattributes and enforce correct line endings for endings-sensitive files in the repo (.sh, .bat). Then .bat files will have Windows endings even when checked out on Linux and "unzip -aa" can be replaced with "unzip".

PS. it seems Win10 can execute .bat files even with Unix line endings. Maybe Server 2016 can too.
Comment 32 Nikita Nemkin CLA 2019-06-12 04:36:53 EDT
A simpler Jenkins-only fix is to drop replace "unzip -aa" with "unzip" and run unix2dos build.bat afterwards (if dos2unix is available on the build machine).
Comment 33 Niraj Modi CLA 2019-06-12 05:31:05 EDT
(In reply to Nikita Nemkin from comment #32)
> A simpler Jenkins-only fix is to drop replace "unzip -aa" with "unzip" and
> run unix2dos build.bat afterwards (if dos2unix is available on the build
> machine).

Tried replacing the "unzip -aa" option with "unzip" and Windows build job is working fine, will give a try with your patch now.
Comment 34 Eclipse Genie CLA 2019-06-12 05:31:38 EDT
New Gerrit change created: https://git.eclipse.org/r/143813
Comment 36 Niraj Modi CLA 2019-06-12 05:42:45 EDT
(In reply to Niraj Modi from comment #33)
> (In reply to Nikita Nemkin from comment #32)
> > A simpler Jenkins-only fix is to drop replace "unzip -aa" with "unzip" and
> > run unix2dos build.bat afterwards (if dos2unix is available on the build
> > machine).
> 
> Tried replacing the "unzip -aa" option with "unzip" and Windows build job is
> working fine, will give a try with your patch now.

Thanks Nikita removing the -aa option works just fine. I have merged your patch and the change should be there in next IBuild.
Comment 37 Niraj Modi CLA 2019-06-12 05:50:55 EDT
By reverting the patches through gerrit, we loose track of the original author of the code change, I will fix this shortly using EGit.Thanks!
Comment 38 Niraj Modi CLA 2019-06-12 06:02:35 EDT
(In reply to Niraj Modi from comment #37)
> By reverting the patches through gerrit, we loose track of the original
> author of the code change, I will fix this shortly using EGit.Thanks!

Done via below git commits, revert via below git commit:
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=a551d9cf6c769c4e64f0c41f5cba6c7e8ef9d193

Final git patch with correct author via below git commit:
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=a09fd5ce015e751c6e1b365e563e6cba8a65fa3d
Comment 39 Eclipse Genie CLA 2019-06-13 02:48:47 EDT
New Gerrit change created: https://git.eclipse.org/r/143924
Comment 41 Nikita Nemkin CLA 2019-06-13 02:54:31 EDT
(In reply to Lars Vogel from comment #23)
> Thanks Nikita. Can you please add this new functionality to the N&N for 4.13?

Done.
Comment 42 Lars Vogel CLA 2019-06-13 03:53:16 EDT
(In reply to Nikita Nemkin from comment #41)
> (In reply to Lars Vogel from comment #23)
> > Thanks Nikita. Can you please add this new functionality to the N&N for 4.13?
> 
> Done.

Thanks!
Comment 43 Lakshmi P Shanmugam CLA 2019-07-10 07:15:05 EDT
Should we remove the HINT tags from the javadoc for these styles since now?
Comment 44 Niraj Modi CLA 2019-07-10 07:35:35 EDT
(In reply to Lakshmi Shanmugam from comment #43)
> Should we remove the HINT tags from the javadoc for these styles since now?

Yes, now we Support SWT.ICON_SEARCH and SWT.ICON_CANCEL on all platforms.
Comment 45 Eclipse Genie CLA 2019-07-10 07:55:28 EDT
New Gerrit change created: https://git.eclipse.org/r/145850
Comment 47 Niraj Modi CLA 2019-07-11 05:12:33 EDT
Verified in Build id: I20190710-1800 on Win7.