diff options
author | Steve Northover <steve> | 2005-06-09 19:55:29 +0000 |
---|---|---|
committer | Steve Northover <steve> | 2005-06-09 19:55:29 +0000 |
commit | c2a3df1a5f68cf5dd9c3452b58c3950b7c421126 (patch) | |
tree | a772eb464da2808cd57cefa584388439ac6e6ba2 /bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java | |
parent | 45efec4374d4e8d506f2e8938e6db947d7312256 (diff) | |
download | eclipse.platform.swt-c2a3df1a5f68cf5dd9c3452b58c3950b7c421126.tar.gz eclipse.platform.swt-c2a3df1a5f68cf5dd9c3452b58c3950b7c421126.tar.xz eclipse.platform.swt-c2a3df1a5f68cf5dd9c3452b58c3950b7c421126.zip |
choose the best icon
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java index ebba6f95b4..49140c1c4b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java @@ -163,6 +163,12 @@ protected void checkSubclass () { } void _setImages (Image [] images) { + if (images != null && images.length > 1) { + Image [] bestImages = new Image [images.length]; + System.arraycopy (images, 0, bestImages, 0, images.length); + sort (bestImages); + images = bestImages; + } int /*long*/ pixbufs = 0; if (images != null) { for (int i = 0; i < images.length; i++) { @@ -196,6 +202,21 @@ void add (Menu menu) { menus = newMenus; } +int compare (ImageData data1, ImageData data2) { + if (data1.width == data2.width && data1.height == data2.height) { + int transparent1 = data1.getTransparencyType (); + int transparent2 = data2.getTransparencyType (); + if (transparent1 == SWT.TRANSPARENCY_ALPHA) return -1; + if (transparent2 == SWT.TRANSPARENCY_ALPHA) return 1; + if (transparent1 == SWT.TRANSPARENCY_MASK) return -1; + if (transparent2 == SWT.TRANSPARENCY_MASK) return 1; + if (transparent1 == SWT.TRANSPARENCY_PIXEL) return -1; + if (transparent2 == SWT.TRANSPARENCY_PIXEL) return 1; + return 0; + } + return data1.width > data2.width || data1.height > data2.height ? -1 : 1; +} + Control computeTabGroup () { return this; } @@ -666,6 +687,30 @@ public void setText (String string) { text = string; } +void sort (Image [] images) { + /* Shell Sort from K&R, pg 108 */ + int length = images.length; + if (length <= 1) return; + ImageData [] datas = new ImageData [length]; + for (int i = 0; i < length; i++) { + datas [i] = images [i].getImageData (); + } + for (int gap=length/2; gap>0; gap/=2) { + for (int i=gap; i<length; i++) { + for (int j=i-gap; j>=0; j-=gap) { + if (compare (datas [j], datas [j + gap]) >= 0) { + Image swap = images [j]; + images [j] = images [j + gap]; + images [j + gap] = swap; + ImageData swapData = datas [j]; + datas [j] = datas [j + gap]; + datas [j + gap] = swapData; + } + } + } + } +} + boolean traverseItem (boolean next) { return false; } |