diff options
23 files changed, 1522 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/.classpath_carbon b/bundles/org.eclipse.swt/.classpath_carbon index 5b41c94a8a..cdb68d6467 100644 --- a/bundles/org.eclipse.swt/.classpath_carbon +++ b/bundles/org.eclipse.swt/.classpath_carbon @@ -7,6 +7,7 @@ <classpathentry kind="src" path="Eclipse SWT/emulated/bidi"/> <classpathentry kind="src" path="Eclipse SWT/emulated/coolbar"/> <classpathentry kind="src" path="Eclipse SWT/emulated/expand"/> + <classpathentry kind="src" path="Eclipse SWT/emulated/taskbar"/> <classpathentry kind="src" path="Eclipse SWT PI/common"/> <classpathentry kind="src" path="Eclipse SWT PI/carbon"> <attributes> diff --git a/bundles/org.eclipse.swt/.classpath_carbon_j2me b/bundles/org.eclipse.swt/.classpath_carbon_j2me index a6ac44c75d..22cc82f72d 100644 --- a/bundles/org.eclipse.swt/.classpath_carbon_j2me +++ b/bundles/org.eclipse.swt/.classpath_carbon_j2me @@ -6,6 +6,7 @@ <classpathentry kind="src" path="Eclipse SWT/emulated/coolbar"/> <classpathentry kind="src" path="Eclipse SWT/emulated/tray"/> <classpathentry kind="src" path="Eclipse SWT/emulated/expand"/> + <classpathentry kind="src" path="Eclipse SWT/emulated/taskbar"/> <classpathentry kind="src" path="Eclipse SWT/common"/> <classpathentry kind="src" path="Eclipse SWT/common_j2me"/> <classpathentry kind="src" path="Eclipse SWT PI/common"/> diff --git a/bundles/org.eclipse.swt/.classpath_gtk b/bundles/org.eclipse.swt/.classpath_gtk index d49778a93d..2ae41a46d5 100644 --- a/bundles/org.eclipse.swt/.classpath_gtk +++ b/bundles/org.eclipse.swt/.classpath_gtk @@ -5,6 +5,7 @@ <classpathentry kind="src" path="Eclipse SWT/cairo"/> <classpathentry kind="src" path="Eclipse SWT/emulated/bidi"/> <classpathentry kind="src" path="Eclipse SWT/emulated/coolbar"/> + <classpathentry kind="src" path="Eclipse SWT/emulated/taskbar"/> <classpathentry kind="src" path="Eclipse SWT/common"/> <classpathentry kind="src" path="Eclipse SWT/common_j2se"/> <classpathentry kind="src" path="Eclipse SWT PI/gtk"> diff --git a/bundles/org.eclipse.swt/.classpath_gtk_j2me b/bundles/org.eclipse.swt/.classpath_gtk_j2me index edb1b635bf..c715d37dae 100644 --- a/bundles/org.eclipse.swt/.classpath_gtk_j2me +++ b/bundles/org.eclipse.swt/.classpath_gtk_j2me @@ -4,6 +4,7 @@ <classpathentry kind="src" path="Eclipse SWT/gtk"/> <classpathentry kind="src" path="Eclipse SWT/emulated/bidi"/> <classpathentry kind="src" path="Eclipse SWT/emulated/coolbar"/> + <classpathentry kind="src" path="Eclipse SWT/emulated/taskbar"/> <classpathentry kind="src" path="Eclipse SWT/common"/> <classpathentry kind="src" path="Eclipse SWT/common_j2me"/> <classpathentry kind="src" path="Eclipse SWT PI/common"/> diff --git a/bundles/org.eclipse.swt/.classpath_motif b/bundles/org.eclipse.swt/.classpath_motif index db459dbb07..42051ebea5 100755 --- a/bundles/org.eclipse.swt/.classpath_motif +++ b/bundles/org.eclipse.swt/.classpath_motif @@ -12,6 +12,7 @@ <classpathentry kind="src" path="Eclipse SWT/emulated/expand"/> <classpathentry kind="src" path="Eclipse SWT/emulated/tooltip"/> <classpathentry kind="src" path="Eclipse SWT/emulated/ime"/> + <classpathentry kind="src" path="Eclipse SWT/emulated/taskbar"/> <classpathentry kind="src" path="Eclipse SWT/common"/> <classpathentry kind="src" path="Eclipse SWT/common_j2se"/> <classpathentry kind="src" path="Eclipse SWT PI/motif"> diff --git a/bundles/org.eclipse.swt/.classpath_motif_j2me b/bundles/org.eclipse.swt/.classpath_motif_j2me index bb3e94ac63..c653b038c0 100644 --- a/bundles/org.eclipse.swt/.classpath_motif_j2me +++ b/bundles/org.eclipse.swt/.classpath_motif_j2me @@ -11,6 +11,7 @@ <classpathentry kind="src" path="Eclipse SWT/emulated/expand"/> <classpathentry kind="src" path="Eclipse SWT/emulated/tooltip"/> <classpathentry kind="src" path="Eclipse SWT/emulated/ime"/> + <classpathentry kind="src" path="Eclipse SWT/emulated/taskbar"/> <classpathentry kind="src" path="Eclipse SWT/common"/> <classpathentry kind="src" path="Eclipse SWT/common_j2me"/> <classpathentry kind="src" path="Eclipse SWT PI/common"/> diff --git a/bundles/org.eclipse.swt/.classpath_photon b/bundles/org.eclipse.swt/.classpath_photon index 4f3d4fa187..3c7f8847ab 100755 --- a/bundles/org.eclipse.swt/.classpath_photon +++ b/bundles/org.eclipse.swt/.classpath_photon @@ -12,6 +12,7 @@ <classpathentry kind="src" path="Eclipse SWT/emulated/expand"/> <classpathentry kind="src" path="Eclipse SWT/emulated/tooltip"/> <classpathentry kind="src" path="Eclipse SWT/emulated/ime"/> + <classpathentry kind="src" path="Eclipse SWT/emulated/taskbar"/> <classpathentry kind="src" path="Eclipse SWT/common"/> <classpathentry kind="src" path="Eclipse SWT/common_j2se"/> <classpathentry kind="src" path="Eclipse SWT PI/common"/> diff --git a/bundles/org.eclipse.swt/.classpath_photon_j2me b/bundles/org.eclipse.swt/.classpath_photon_j2me index 4005c9a241..ab62deef8d 100644 --- a/bundles/org.eclipse.swt/.classpath_photon_j2me +++ b/bundles/org.eclipse.swt/.classpath_photon_j2me @@ -11,6 +11,7 @@ <classpathentry kind="src" path="Eclipse SWT/emulated/expand"/> <classpathentry kind="src" path="Eclipse SWT/emulated/tooltip"/> <classpathentry kind="src" path="Eclipse SWT/emulated/ime"/> + <classpathentry kind="src" path="Eclipse SWT/emulated/taskbar"/> <classpathentry kind="src" path="Eclipse SWT/common"/> <classpathentry kind="src" path="Eclipse SWT/common_j2me"/> <classpathentry kind="src" path="Eclipse SWT PI/common"/> diff --git a/bundles/org.eclipse.swt/.classpath_wpf b/bundles/org.eclipse.swt/.classpath_wpf index 3ecce1fc1c..9d2426f0ec 100644 --- a/bundles/org.eclipse.swt/.classpath_wpf +++ b/bundles/org.eclipse.swt/.classpath_wpf @@ -16,6 +16,7 @@ <classpathentry kind="src" path="Eclipse SWT/emulated/bidi"/> <classpathentry kind="src" path="Eclipse SWT/emulated/tooltip"/> <classpathentry kind="src" path="Eclipse SWT/emulated/ime"/> + <classpathentry kind="src" path="Eclipse SWT/emulated/taskbar"/> <classpathentry kind="src" path="Eclipse SWT Accessibility/emulated"/> <classpathentry kind="src" path="Eclipse SWT Accessibility/common"/> <classpathentry kind="src" path="Eclipse SWT AWT/emulated"/> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java index 6d9c52943e..54f5d5621c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java @@ -2088,6 +2088,11 @@ public Image getSystemImage (int id) { return null; } +public TaskBar getSystemTaskBar () { + checkDevice (); + return null; +} + /** * Returns the single instance of the system tray or null * when there is no system tray available for the platform. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index be81e6fa5e..e459ff255f 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -179,6 +179,9 @@ public class Display extends Device { TrayItem currentTrayItem; Menu trayItemMenu; + /* TaskBar */ + TaskBar taskBar; + /* System Resources */ Image errorImage, infoImage, warningImage; Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1]; @@ -1863,6 +1866,13 @@ public Tray getSystemTray () { return tray = new Tray (this, SWT.NONE); } +public TaskBar getSystemTaskBar () { + checkDevice (); + if (taskBar != null) return taskBar; + taskBar = new TaskBar (this, SWT.NONE); + return taskBar; +} + /** * Returns the user-interface thread for the receiver. * @@ -3282,6 +3292,8 @@ protected void release () { } if (tray != null) tray.dispose (); tray = null; + if (taskBar != null) taskBar.dispose (); + taskBar = null; while (readAndDispatch ()) {} if (disposeList != null) { for (int i=0; i<disposeList.length; i++) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TaskBar.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TaskBar.java new file mode 100644 index 0000000000..142fb6af41 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TaskBar.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.widgets; + + +import org.eclipse.swt.*; + +/** + * Instances of this class represent the system task bar. + * + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * + * @see Display#getSystemTaskBar + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * + * @since 3.6 + * + * @noextend This class is not intended to be subclassed by clients. + */ +public class TaskBar extends Widget { + int itemCount; + TaskBarItem [] items = new TaskBarItem [4]; + +TaskBar (Display display, int style) { + if (display == null) display = Display.getCurrent (); + if (display == null) display = Display.getDefault (); + if (!display.isValidThread ()) { + error (SWT.ERROR_THREAD_INVALID_ACCESS); + } + this.display = display; + reskinWidget (); +} + +void createItem (TaskBarItem item, int index) { + if (index == -1) index = itemCount; + if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); + if (itemCount == items.length) { + TaskBarItem [] newItems = new TaskBarItem [items.length + 4]; + System.arraycopy (items, 0, newItems, 0, items.length); + items = newItems; + } + System.arraycopy (items, index, items, index + 1, itemCount++ - index); + items [index] = item; +} + +void createItems () { + getItem (null); +} + +void destroyItem (TaskBarItem item) { + int index = 0; + while (index < itemCount) { + if (items [index] == item) break; + index++; + } + if (index == itemCount) return; + System.arraycopy (items, index + 1, items, index, --itemCount - index); + items [itemCount] = null; +} + +/** + * Returns the item at the given, zero-relative index in the + * receiver. Throws an exception if the index is out of range. + * + * @param index the index of the item to return + * @return the item at the given index + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public TaskBarItem getItem (int index) { + checkWidget (); + createItems (); + if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); + return items [index]; +} + +/** + * Returns the number of items contained in the receiver. + * + * @return the number of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public int getItemCount () { + checkWidget (); + createItems (); + return itemCount; +} + +public TaskBarItem getItem (Shell shell) { + checkWidget (); + for (int i = 0; i < itemCount; i++) { + if (items [i] != null && items [i].shell == shell) { + return items [i]; + } + } + TaskBarItem item = null; + if (shell == null) { + item = new TaskBarItem (this, SWT.NONE); + } else { + // on the Mac only the application item is supported +// TaskBarItem item = new TaskBarItem (this, SWT.NONE); +// item.setShell (shell); + } + return item; +} + +/** + * Returns an array of <code>TaskBarItem</code>s which are the items + * in the receiver. + * <p> + * Note: This is not the actual structure used by the receiver + * to maintain its list of items, so modifying the array will + * not affect the receiver. + * </p> + * + * @return the items in the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public TaskBarItem [] getItems () { + checkWidget (); + createItems (); + TaskBarItem [] result = new TaskBarItem [itemCount]; + System.arraycopy (items, 0, result, 0, result.length); + return result; +} + +void releaseChildren (boolean destroy) { + if (items != null) { + for (int i=0; i<items.length; i++) { + TaskBarItem item = items [i]; + if (item != null && !item.isDisposed ()) { + item.release (false); + } + } + items = null; + } + super.releaseChildren (destroy); +} + +void releaseParent () { + super.releaseParent (); + if (display.taskBar == this) display.taskBar = null; +} + +void reskinChildren (int flags) { + if (items != null) { + for (int i=0; i<items.length; i++) { + TaskBarItem item = items [i]; + if (item != null) item.reskin (flags); + } + } + super.reskinChildren (flags); +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TaskBarItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TaskBarItem.java new file mode 100644 index 0000000000..2968a762bf --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TaskBarItem.java @@ -0,0 +1,270 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.widgets; + + +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.cocoa.*; + +/** + * Instances of this class represent a taskbar item. + * + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * + * @since 3.6 + * + * @noextend This class is not intended to be subclassed by clients. + */ +public class TaskBarItem extends Item { + TaskBar parent; + Shell shell; + NSImage defaultImage; + int progress, iProgress, progressState = SWT.DEFAULT; + Image overlayImage; + String overlayText = ""; + + static final int PROGRESS_MAX = 100; + static final int PROGRESS_TIMER = 350; + static final int PROGRESS_BARS = 7; + +/** + * Constructs a new instance of this class given its parent + * (which must be a <code>Tray</code>) and a style value + * describing its behavior and appearance. The item is added + * to the end of the items maintained by its parent. + * <p> + * The style value is either one of the style constants defined in + * class <code>SWT</code> which is applicable to instances of this + * class, or must be built by <em>bitwise OR</em>'ing together + * (that is, using the <code>int</code> "|" operator) two or more + * of those <code>SWT</code> style constants. The class description + * lists the style constants that are applicable to the class. + * Style bits are also inherited from superclasses. + * </p> + * + * @param parent a composite control which will be the parent of the new instance (cannot be null) + * @param style the style of control to construct + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> + * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> + * </ul> + * + * @see SWT + * @see Widget#checkSubclass + * @see Widget#getStyle + */ +TaskBarItem (TaskBar parent, int style) { + super (parent, style); + this.parent = parent; + parent.createItem (this, -1); + createWidget (); +} + +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} + +void createWidget () { + NSApplication app = NSApplication.sharedApplication (); + NSImage image = app.applicationIconImage (); + defaultImage = new NSImage (image.copy ()); +} + +void destroyWidget () { + parent.destroyItem (this); + releaseHandle (); +} + +public Image getOverlayImage () { + checkWidget (); + return overlayImage; +} + +public String getOverlayText () { + checkWidget (); + return overlayText; +} + +/** + * Returns the receiver's parent, which must be a <code>TaskBar</code>. + * + * @return the receiver's parent + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + */ +public TaskBar getParent () { + checkWidget (); + return parent; +} + +public int getProgress () { + checkWidget (); + return progress; +} + +public int getProgressState () { + checkWidget (); + return progressState; +} + +void releaseHandle () { + super.releaseHandle (); + parent = null; + if (defaultImage != null) defaultImage.release (); + defaultImage = null; +} + +void releaseWidget () { + super.releaseWidget (); + overlayImage = null; + overlayText = null; + shell = null; +} + +public void setOverlayImage (Image image) { + checkWidget (); + if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); + overlayImage = image; + updateOverlayText (image != null ? null : overlayText); + updateImage (); +} + +public void setOverlayText (String string) { + checkWidget (); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + overlayText = string; + updateOverlayText (string); + updateImage (); +} + +public void setProgress (int progress) { + checkWidget (); + progress = Math.max (0, Math.min (progress, PROGRESS_MAX)); + if (this.progress == progress) return; + this.progress = progress; + updateImage (); +} + +public void setProgressState (int progressState) { + checkWidget (); + if (this.progressState == progressState) return; + this.progressState = progressState; + updateImage (); +} + +void setShell (Shell shell) { + this.shell = shell; + shell.addListener (SWT.Dispose, new Listener () { + public void handleEvent (Event event) { + if (isDisposed ()) return; + dispose (); + } + }); +} + +void updateImage () { + boolean drawProgress = progress != 0 && progressState != SWT.DEFAULT; + boolean drawIntermidiate = progressState == SWT.INDETERMINATE; + NSApplication app = NSApplication.sharedApplication (); + NSDockTile dock = app.dockTile (); + boolean drawImage = overlayImage != null && dock.badgeLabel () == null; + if (!drawImage && !drawProgress && !drawIntermidiate) { + app.setApplicationIconImage (null); + return; + } + + NSSize size = defaultImage.size (); + NSImage newImage = (NSImage)new NSImage().alloc (); + newImage = newImage.initWithSize (size); + NSBitmapImageRep rep = (NSBitmapImageRep)new NSBitmapImageRep ().alloc (); + rep = rep.initWithBitmapDataPlanes (0, (int)size.width, (int)size.height, 8, 4, true, false, OS.NSDeviceRGBColorSpace, OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, (int)size.width * 4, 32); + newImage.addRepresentation (rep); + rep.release (); + + NSRect rect = new NSRect (); + rect.height = size.height; + rect.width = size.width; + newImage.lockFocus (); + defaultImage.drawInRect (rect, rect, OS.NSCompositeSourceOver, 1); + if (drawImage) { + NSImage badgetImage = overlayImage.handle; + NSSize badgeSize = badgetImage.size (); + NSRect srcRect = new NSRect (); + srcRect.height = badgeSize.height; + srcRect.width = badgeSize.width; + NSRect dstRect = new NSRect (); + dstRect.x = size.width / 2; + dstRect.height = size.height / 2; + dstRect.width = size.width / 2; + badgetImage.drawInRect(dstRect, srcRect, OS.NSCompositeSourceOver, 1); + } + if (drawIntermidiate || drawProgress) { + switch (progressState) { + case SWT.ERROR: + NSColor.colorWithDeviceRed (1, 0, 0, 0.6f).setFill (); + break; + case SWT.PAUSED: + NSColor.colorWithDeviceRed (1, 1, 0, 0.6f).setFill (); + break; + default: + NSColor.colorWithDeviceRed (1, 1, 1, 0.6f).setFill (); + } + rect.width = size.width / (PROGRESS_BARS * 2 - 1); + rect.height = size.height / 3; + int count; + if (drawIntermidiate) { + count = iProgress; + iProgress = (iProgress + 1) % (PROGRESS_BARS + 1); + getDisplay ().timerExec (PROGRESS_TIMER, new Runnable () { + public void run () { + updateImage (); + } + }); + } else { + count = progress * PROGRESS_BARS / PROGRESS_MAX; + } + for (int i = 0; i <= count; i++) { + rect.x = i * 2 * rect.width; + NSBezierPath.fillRect (rect); + } + } + newImage.unlockFocus (); + app.setApplicationIconImage (newImage); + newImage.release (); +} + +void updateOverlayText (String string) { + NSApplication app = NSApplication.sharedApplication (); + NSDockTile dock = app.dockTile (); + if (string != null && string.length () > 0) { + dock.setBadgeLabel (NSString.stringWith (string)); + } else { + dock.setBadgeLabel (null); + } +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/taskbar/org/eclipse/swt/widgets/TaskBar.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/taskbar/org/eclipse/swt/widgets/TaskBar.java new file mode 100644 index 0000000000..43b387d35b --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/emulated/taskbar/org/eclipse/swt/widgets/TaskBar.java @@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.widgets; + + +import org.eclipse.swt.*; + +/** + * Instances of this class represent the system task bar. + * + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * + * @see Display#getSystemTaskBar + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * + * @since 3.6 + * + * @noextend This class is not intended to be subclassed by clients. + */ +public class TaskBar extends Widget { + int itemCount; + TaskBarItem [] items = new TaskBarItem [4]; + +TaskBar (Display display, int style) { + if (display == null) display = Display.getCurrent (); + if (display == null) display = Display.getDefault (); + if (!display.isValidThread ()) { + error (SWT.ERROR_THREAD_INVALID_ACCESS); + } + this.display = display; + reskinWidget (); +} + +void createItem (TaskBarItem item, int index) { + if (index == -1) index = itemCount; + if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); + if (itemCount == items.length) { + TaskBarItem [] newItems = new TaskBarItem [items.length + 4]; + System.arraycopy (items, 0, newItems, 0, items.length); + items = newItems; + } + System.arraycopy (items, index, items, index + 1, itemCount++ - index); + items [index] = item; +} + +void createItems () { +} + +void destroyItem (TaskBarItem item) { + int index = 0; + while (index < itemCount) { + if (items [index] == item) break; + index++; + } + if (index == itemCount) return; + System.arraycopy (items, index + 1, items, index, --itemCount - index); + items [itemCount] = null; +} + +/** + * Returns the item at the given, zero-relative index in the + * receiver. Throws an exception if the index is out of range. + * + * @param index the index of the item to return + * @return the item at the given index + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public TaskBarItem getItem (int index) { + checkWidget (); + createItems (); + if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); + return items [index]; +} + +/** + * Returns the number of items contained in the receiver. + * + * @return the number of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public int getItemCount () { + checkWidget (); + createItems (); + return itemCount; +} + +public TaskBarItem getItem (Shell shell) { + checkWidget (); + return null; +} + +/** + * Returns an array of <code>TaskBarItem</code>s which are the items + * in the receiver. + * <p> + * Note: This is not the actual structure used by the receiver + * to maintain its list of items, so modifying the array will + * not affect the receiver. + * </p> + * + * @return the items in the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public TaskBarItem [] getItems () { + checkWidget (); + createItems (); + TaskBarItem [] result = new TaskBarItem [itemCount]; + System.arraycopy (items, 0, result, 0, result.length); + return result; +} + +void releaseChildren (boolean destroy) { + if (items != null) { + for (int i=0; i<items.length; i++) { + TaskBarItem item = items [i]; + if (item != null && !item.isDisposed ()) { + item.release (false); + } + } + items = null; + } + super.releaseChildren (destroy); +} + +void releaseParent () { + super.releaseParent (); +// if (display.taskBar == this) display.taskBar = null; +} + +void reskinChildren (int flags) { + if (items != null) { + for (int i=0; i<items.length; i++) { + TaskBarItem item = items [i]; + if (item != null) item.reskin (flags); + } + } + super.reskinChildren (flags); +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/taskbar/org/eclipse/swt/widgets/TaskBarItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/taskbar/org/eclipse/swt/widgets/TaskBarItem.java new file mode 100644 index 0000000000..3bc57ee177 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/emulated/taskbar/org/eclipse/swt/widgets/TaskBarItem.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.widgets; + + +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + +/** + * Instances of this class represent a taskbar item. + * + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * + * @since 3.6 + * + * @noextend This class is not intended to be subclassed by clients. + */ +public class TaskBarItem extends Item { + TaskBar parent; + Shell shell; + int progress, progressState = SWT.DEFAULT; + Image overlayImage; + String overlayText = ""; + + static final int PROGRESS_MAX = 100; +/** + * Constructs a new instance of this class given its parent + * (which must be a <code>Tray</code>) and a style value + * describing its behavior and appearance. The item is added + * to the end of the items maintained by its parent. + * <p> + * The style value is either one of the style constants defined in + * class <code>SWT</code> which is applicable to instances of this + * class, or must be built by <em>bitwise OR</em>'ing together + * (that is, using the <code>int</code> "|" operator) two or more + * of those <code>SWT</code> style constants. The class description + * lists the style constants that are applicable to the class. + * Style bits are also inherited from superclasses. + * </p> + * + * @param parent a composite control which will be the parent of the new instance (cannot be null) + * @param style the style of control to construct + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> + * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> + * </ul> + * + * @see SWT + * @see Widget#checkSubclass + * @see Widget#getStyle + */ +TaskBarItem (TaskBar parent, int style) { + super (parent, style); + this.parent = parent; + parent.createItem (this, -1); +} + +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} + +void destroyWidget () { + parent.destroyItem (this); + releaseHandle (); +} + +public Image getOverlayImage () { + checkWidget(); + return overlayImage; +} + +public String getOverlayText () { + checkWidget(); + return overlayText; +} + +/** + * Returns the receiver's parent, which must be a <code>TaskBar</code>. + * + * @return the receiver's parent + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + */ +public TaskBar getParent () { + checkWidget (); + return parent; +} + +public int getProgress () { + checkWidget (); + return progress; +} + +public int getProgressState () { + checkWidget (); + return progressState; +} + +void releaseHandle () { + super.releaseHandle (); + parent = null; +} + +void releaseWidget () { + super.releaseWidget (); + overlayImage = null; + overlayText = null; +} + +/** + * Sets the receiver's overlay image. + * + * @param overlayImage the new overlay image + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setOverlayImage (Image overlayImage) { + checkWidget (); + if (overlayImage != null && overlayImage.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); + this.overlayImage = overlayImage; +} + +public void setOverlayText (String overlayText) { + checkWidget (); + if (overlayText == null) error (SWT.ERROR_NULL_ARGUMENT); + this.overlayText = overlayText; +} + +public void setProgressState (int progressState) { + checkWidget (); + if (this.progressState == progressState) return; + this.progressState = progressState; +} + +public void setProgress (int progress) { + checkWidget (); + progress = Math.max(0, Math.min(progress, PROGRESS_MAX)); + if (this.progress == progress) return; + this.progress = progress; +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 69b87d01ef..aa20508085 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -2300,6 +2300,11 @@ public Font getSystemFont () { return systemFont = Font.gtk_new (this, defaultFont); } +public TaskBar getSystemTaskBar () { + checkDevice (); + return null; +} + /** * Returns the single instance of the system tray or null * when there is no system tray available for the platform. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java index 4315f3386b..1d6112c29e 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java @@ -1951,6 +1951,10 @@ public Image getSystemImage (int style) { if (imagePixmap == 0) return null; return Image.motif_new (this, SWT.ICON, imagePixmap, maskPixmap); } +public TaskBar getSystemTaskBar () { + checkDevice (); + return null; +} /** * Returns the single instance of the system tray or null * when there is no system tray available for the platform. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java index de7dc27068..6709de5685 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java @@ -1300,6 +1300,11 @@ public Image getSystemImage (int id) { return null; } +public TaskBar getSystemTaskBar () { + checkDevice (); + return null; +} + /** * Returns the single instance of the system tray or null * when there is no system tray available for the platform. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index ba87e332f8..9ddb649948 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -215,6 +215,9 @@ public class Display extends Device { Tray tray; int nextTrayId; + /* TaskBar */ + TaskBar taskBar; + /* Timers */ int /*long*/ [] timerIds; Runnable [] timerList; @@ -2464,6 +2467,27 @@ public Image getSystemImage (int id) { } /** + * Returns the single instance of the system taskBar or null + * when there is no system taskBar available for the platform. + * + * @return the system taskBar or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.6 + */ +public TaskBar getSystemTaskBar () { + checkDevice (); + if (taskBar != null) return taskBar; + if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 1)) { + taskBar = new TaskBar (this, SWT.NONE); + } + return taskBar; +} + +/** * Returns the single instance of the system tray or null * when there is no system tray available for the platform. * @@ -3628,6 +3652,8 @@ protected void release () { } if (tray != null) tray.dispose (); tray = null; + if (taskBar != null) taskBar.dispose (); + taskBar = null; while (readAndDispatch ()) {} if (disposeList != null) { for (int i=0; i<disposeList.length; i++) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBar.java new file mode 100644 index 0000000000..bc94e3b848 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBar.java @@ -0,0 +1,222 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.widgets; + + +import org.eclipse.swt.internal.win32.*; +import org.eclipse.swt.*; + +/** + * Instances of this class represent the system task bar. + * + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * + * @see Display#getSystemTaskBar + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * + * @since 3.6 + * + * @noextend This class is not intended to be subclassed by clients. + */ +public class TaskBar extends Widget { + int itemCount; + TaskBarItem [] items = new TaskBarItem [4]; + int /*long*/ mTaskbarList3; + + static final byte [] CLSID_TaskbarList = new byte [16]; + static final byte [] IID_ITaskbarList3 = new byte [16]; + static { + OS.IIDFromString ("{56FDF344-FD6D-11d0-958A-006097C9A090}\0".toCharArray (), CLSID_TaskbarList); //$NON-NLS-1$ + OS.IIDFromString ("{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}\0".toCharArray (), IID_ITaskbarList3); //$NON-NLS-1$ + } + +TaskBar (Display display, int style) { + if (display == null) display = Display.getCurrent (); + if (display == null) display = Display.getDefault (); + if (!display.isValidThread ()) { + error (SWT.ERROR_THREAD_INVALID_ACCESS); + } + this.display = display; + createHandle (); + reskinWidget (); +} + +void createHandle () { + int /*long*/[] ppv = new int /*long*/ [1]; + int hr = OS.CoCreateInstance (CLSID_TaskbarList, 0, OS.CLSCTX_INPROC_SERVER, IID_ITaskbarList3, ppv); + if (hr != OS.S_OK) error (SWT.ERROR_NO_HANDLES); + mTaskbarList3 = ppv [0]; +} + +void createItem (TaskBarItem item, int index) { + if (index == -1) index = itemCount; + if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); + if (itemCount == items.length) { + TaskBarItem [] newItems = new TaskBarItem [items.length + 4]; + System.arraycopy (items, 0, newItems, 0, items.length); + items = newItems; + } + System.arraycopy (items, index, items, index + 1, itemCount++ - index); + items [index] = item; +} + +void createItems () { + Shell [] shells = display.getShells (); + for (int i = 0; i < shells.length; i++) { + getItem (shells[i]); + } +} + +void destroyItem (TaskBarItem item) { + int index = 0; + while (index < itemCount) { + if (items [index] == item) break; + index++; + } + if (index == itemCount) return; + System.arraycopy (items, index + 1, items, index, --itemCount - index); + items [itemCount] = null; +} + +/** + * Returns the item at the given, zero-relative index in the + * receiver. Throws an exception if the index is out of range. + * + * @param index the index of the item to return + * @return the item at the given index + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public TaskBarItem getItem (int index) { + checkWidget (); + createItems (); + if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); + return items [index]; +} + +/** + * Returns the number of items contained in the receiver. + * + * @return the number of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public int getItemCount () { + checkWidget (); + createItems (); + return itemCount; +} + +/** + * Returns the task bar item for the given <code>shell</code> or the task bar + * item for the application if the <code>shell</code> argument is <code>null</code>. + * If the requested item is not supported by the platform it returns <code>null</code>. + * + * @param shell the shell for which the task bar item is requested, or null to request the application item + * @return the task bar item at the given shell or the application + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public TaskBarItem getItem (Shell shell) { + checkWidget (); + for (int i = 0; i < items.length; i++) { + if (items [i] != null && items [i].shell == shell) { + return items [i]; + } + } + // Windows only supports shell item + TaskBarItem item = null; + if (shell != null) { + item = new TaskBarItem (this, SWT.NONE); + item.setShell (shell); + } + return item; +} + +/** + * Returns an array of <code>TaskBarItem</code>s which are the items + * in the receiver. + * <p> + * Note: This is not the actual structure used by the receiver + * to maintain its list of items, so modifying the array will + * not affect the receiver. + * </p> + * + * @return the items in the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public TaskBarItem [] getItems () { + checkWidget (); + createItems (); + TaskBarItem [] result = new TaskBarItem [itemCount]; + System.arraycopy (items, 0, result, 0, result.length); + return result; +} + +void releaseChildren (boolean destroy) { + if (items != null) { + for (int i=0; i<items.length; i++) { + TaskBarItem item = items [i]; + if (item != null && !item.isDisposed ()) { + item.release (false); + } + } + items = null; + } + super.releaseChildren (destroy); +} + +void releaseParent () { + super.releaseParent (); + if (display.taskBar == this) display.taskBar = null; +} + +void releaseWidget () { + super.releaseWidget (); + if (mTaskbarList3 != 0) { + /* Release() */ + OS.VtblCall (2, mTaskbarList3); + mTaskbarList3 = 0; + } +} + +void reskinChildren (int flags) { + if (items != null) { + for (int i=0; i<items.length; i++) { + TaskBarItem item = items [i]; + if (item != null) item.reskin (flags); + } + } + super.reskinChildren (flags); +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBarItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBarItem.java new file mode 100644 index 0000000000..f5fcf4ae5e --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBarItem.java @@ -0,0 +1,433 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.widgets; + + +import org.eclipse.swt.internal.win32.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + +/** + * Instances of this class represent a task bar item. + * + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * + * @since 3.6 + * + * @noextend This class is not intended to be subclassed by clients. + */ +public class TaskBarItem extends Item { + TaskBar parent; + Shell shell; + int progress, progressState = SWT.DEFAULT; + Image overlayImage; + String overlayText = ""; + + static final int PROGRESS_MAX = 100; + +/** + * Constructs a new instance of this class given its parent + * (which must be a <code>Tray</code>) and a style value + * describing its behavior and appearance. The item is added + * to the end of the items maintained by its parent. + * <p> + * The style value is either one of the style constants defined in + * class <code>SWT</code> which is applicable to instances of this + * class, or must be built by <em>bitwise OR</em>'ing together + * (that is, using the <code>int</code> "|" operator) two or more + * of those <code>SWT</code> style constants. The class description + * lists the style constants that are applicable to the class. + * Style bits are also inherited from superclasses. + * </p> + * + * @param parent a composite control which will be the parent of the new instance (cannot be null) + * @param style the style of control to construct + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> + * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> + * </ul> + * + * @see SWT + * @see Widget#checkSubclass + * @see Widget#getStyle + */ +TaskBarItem (TaskBar parent, int style) { + super (parent, style); + this.parent = parent; + parent.createItem (this, -1); +} + +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} + +void destroyWidget () { + parent.destroyItem (this); + releaseHandle (); +} + +/** + * Returns the receiver's overlay image if it has one, or null + * if it does not. + * + * @return the receiver's overlay image + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Image getOverlayImage () { + checkWidget (); + return overlayImage; +} + +/** + * Returns the receiver's overlay text, which will be an empty + * string if it has never been set. + * + * @return the receiver's overlay text + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public String getOverlayText () { + checkWidget (); + return overlayText; +} + +/** + * Returns the receiver's parent, which must be a <code>TaskBar</code>. + * + * @return the receiver's parent + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + */ +public TaskBar getParent () { + checkWidget (); + return parent; +} + +/** + * Returns the receiver's progress. + * + * @return the receiver's progress + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public int getProgress () { + checkWidget (); + return progress; +} + +/** + * Returns the receiver's progress state. + * + * @return the receiver's progress state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public int getProgressState () { + checkWidget (); + return progressState; +} + +void releaseHandle () { + super.releaseHandle (); + parent = null; +} + +void releaseWidget () { + super.releaseWidget (); + overlayImage = null; + overlayText = null; +} + +/** + * Sets the receiver's overlay image, which may be null + * indicating that no image should be displayed. The bounds + * for the overlay image is determined by the platform and in + * general it should be a small image. + * + * @param overlayImage the new overlay image (may be null) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the overlayImage has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setOverlayImage (Image overlayImage) { + checkWidget (); + if (overlayImage != null && overlayImage.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); + this.overlayImage = overlayImage; + if (overlayImage != null) { + updateImage (); + } else { + if (overlayText.length () != 0) { + updateText (); + } else { + int /*long*/ mTaskbarList3 = parent.mTaskbarList3; + int /*long*/ hwnd = shell.handle; + /* ITaskbarList3::SetOverlayIcon */ + OS.VtblCall (18, mTaskbarList3, hwnd, 0, 0); + } + } +} + +/** + * Sets the receiver's overlay text. The space available to display the + * overlay text is platform dependent and in general it should be no longer + * than a few characters. + * + * @param overlayText the new overlay text + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the overlayText is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setOverlayText (String overlayText) { + checkWidget (); + if (overlayText == null) error (SWT.ERROR_NULL_ARGUMENT); + this.overlayText = overlayText; + if (overlayText.length () != 0) { + updateText (); + } else { + if (overlayImage != null) { + updateImage (); + } else { + int /*long*/ mTaskbarList3 = parent.mTaskbarList3; + int /*long*/ hwnd = shell.handle; + /* ITaskbarList3::SetOverlayIcon */ + OS.VtblCall (18, mTaskbarList3, hwnd, 0, 0); + } + } +} + +/** + * Sets the receiver's progress, the progress represents a percentage and + * should be in range from 0 to 100. The progress is only shown when the progress + * state is different than <code>SWT#DEFAULT</code>. + * + * @param progress the new progress + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * #see {@link #setProgressState(int)} + */ +public void setProgress (int progress) { + checkWidget (); + progress = Math.max (0, Math.min (progress, PROGRESS_MAX)); + if (this.progress == progress) return; + this.progress = progress; + if (progressState == SWT.INDETERMINATE) return; + if (progressState == SWT.DEFAULT) return; + int /*long*/ mTaskbarList3 = parent.mTaskbarList3; + int /*long*/ hwnd = shell.handle; + /* ITaskbarList3::SetProgressValue */ + OS.VtblCall (9, mTaskbarList3, hwnd, (long)progress, (long)PROGRESS_MAX); +} + +/** + * Sets the receiver's progress state, the state can be one of + * the following: + * <p><ul> + * <li>{@link SWT#DEFAULT}</li> + * <li>{@link SWT#NORMAL}</li> + * <li>{@link SWT#PAUSED}</li> + * <li>{@link SWT#ERROR}</li> + * <li>{@link SWT#INDETERMINATE}</li> + * </ul></p> + * + * The percentage of progress shown by the states <code>SWT#NORMAL</code>, <code>SWT#PAUSED</code>, + * <code>SWT#ERROR</code> is set with <code>setProgress()</code>. <br> + * The state <code>SWT#DEFAULT</code> indicates that no progress should be shown. + * + * @param progressState the new progress state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * #see {@link #setProgress(int)} + */ +public void setProgressState (int progressState) { + checkWidget (); + if (this.progressState == progressState) return; + this.progressState = progressState; + int tbpFlags = OS.TBPF_NOPROGRESS; + switch (progressState) { + case SWT.NORMAL: tbpFlags = OS.TBPF_NORMAL; break; + case SWT.ERROR: tbpFlags = OS.TBPF_ERROR; break; + case SWT.PAUSED: tbpFlags = OS.TBPF_PAUSED; break; + case SWT.INDETERMINATE: tbpFlags = OS.TBPF_INDETERMINATE; break; + } + int /*long*/ mTaskbarList3 = parent.mTaskbarList3; + int /*long*/ hwnd = shell.handle; + /* ITaskbarList3::SetProgressValue */ + OS.VtblCall (9, mTaskbarList3, hwnd, (long)progress, (long)PROGRESS_MAX); + /* ITaskbarList3::SetProgressState */ + OS.VtblCall (10, mTaskbarList3, hwnd, tbpFlags); +} + +void setShell (Shell shell) { + this.shell = shell; + shell.addListener (SWT.Dispose, new Listener () { + public void handleEvent (Event event) { + if (isDisposed ()) return; + dispose (); + } + }); +} + +void updateImage () { + Image image2 = null; + int /*long*/ hIcon = 0; + switch (overlayImage.type) { + case SWT.BITMAP: + image2 = Display.createIcon (overlayImage); + hIcon = image2.handle; + break; + case SWT.ICON: + hIcon = overlayImage.handle; + break; + } + int /*long*/ mTaskbarList3 = parent.mTaskbarList3; + int /*long*/ hwnd = shell.handle; + /* ITaskbarList3::SetOverlayIcon */ + OS.VtblCall (18, mTaskbarList3, hwnd, hIcon, 0); + if (image2 != null) image2.dispose (); +} + +void updateText () { + /* Create resources */ + int width = 16, height = 16; + int /*long*/ hdc = OS.GetDC (0); + BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER (); + bmiHeader.biSize = BITMAPINFOHEADER.sizeof; + bmiHeader.biWidth = width; + bmiHeader.biHeight = -height; + bmiHeader.biPlanes = 1; + bmiHeader.biBitCount = 32; + bmiHeader.biCompression = OS.BI_RGB; + byte [] bmi = new byte [BITMAPINFOHEADER.sizeof]; + OS.MoveMemory (bmi, bmiHeader, BITMAPINFOHEADER.sizeof); + int /*long*/ [] pBits = new int /*long*/ [1]; + int /*long*/ hBitmap = OS.CreateDIBSection (0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0); + if (hBitmap == 0) SWT.error (SWT.ERROR_NO_HANDLES); + int /*long*/ dstHdc = OS.CreateCompatibleDC (hdc); + int /*long*/ oldBitmap = OS.SelectObject (dstHdc, hBitmap); + int /*long*/ hMask = OS.CreateBitmap (width, height, 1, 1, null); + if (hMask == 0) SWT.error (SWT.ERROR_NO_HANDLES); + int /*long*/ maskHdc = OS.CreateCompatibleDC (hdc); + int /*long*/ oldMask = OS.SelectObject (maskHdc, hMask); + + /* Draw content */ + OS.PatBlt (maskHdc, 0, 0, width, height, OS.WHITENESS); + int /*long*/ oldBrush = OS.SelectObject (maskHdc, OS.GetStockObject (OS.BLACK_BRUSH)); + OS.RoundRect (maskHdc, 0, 0, width, height, 8, 8); + OS.SelectObject (maskHdc, oldBrush); + + int /*long*/ brush = OS.CreateSolidBrush (OS.GetSysColor (OS.COLOR_HIGHLIGHT)); + oldBrush = OS.SelectObject (dstHdc, brush); + OS.RoundRect (dstHdc, 0, 0, width, height, 8, 8); + OS.SelectObject (dstHdc, oldBrush); + OS.DeleteObject (brush); + + int uFormat = OS.DT_LEFT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; + RECT rect = new RECT (); + TCHAR buffer = new TCHAR (shell.getCodePage (), overlayText, false); + int length = buffer.length(); + int /*long*/ hFont = 0, oldHFont = 0; + NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA (); + info.cbSize = NONCLIENTMETRICS.sizeof; + if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) { + LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfMessageFont : ((NONCLIENTMETRICSA)info).lfMessageFont; + logFont.lfHeight = -10; + hFont = OS.CreateFontIndirect (logFont); + oldHFont = OS.SelectObject (dstHdc, hFont); + OS.DrawText (dstHdc, buffer, length, rect, uFormat | OS.DT_CALCRECT); + if (rect.right > width - 2) { + OS.SelectObject (dstHdc, oldHFont); + OS.DeleteObject (hFont); + logFont.lfHeight = -8; + hFont = OS.CreateFontIndirect (logFont); + OS.SelectObject (dstHdc, hFont); + } + } + OS.DrawText (dstHdc, buffer, length, rect, uFormat | OS.DT_CALCRECT); + OS.OffsetRect (rect, (width - rect.right) / 2, (height - rect.bottom) / 2); + int oldBkMode = OS.SetBkMode (dstHdc, OS.TRANSPARENT); + OS.SetTextColor (dstHdc, OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT)); + OS.DrawText (dstHdc, buffer, length, rect, uFormat); + if (hFont != 0) { + OS.SelectObject (dstHdc, oldHFont); + OS.DeleteObject (hFont); + } + OS.SetBkMode(dstHdc, oldBkMode); + + /* Release resources */ + OS.SelectObject (dstHdc, oldBitmap); + OS.DeleteDC (dstHdc); + OS.SelectObject (maskHdc, oldMask); + OS.DeleteDC (maskHdc); + OS.ReleaseDC (0, hdc); + + ICONINFO iconInfo = new ICONINFO (); + iconInfo.fIcon = true; + iconInfo.hbmColor = hBitmap; + iconInfo.hbmMask = hMask; + int /*long*/ hIcon = OS.CreateIconIndirect (iconInfo); + if (hIcon == 0) SWT.error (SWT.ERROR_NO_HANDLES); + OS.DeleteObject (hBitmap); + OS.DeleteObject (hMask); + + int /*long*/ mTaskbarList3 = parent.mTaskbarList3; + int /*long*/ hwnd = shell.handle; + /* ITaskbarList3::SetOverlayIcon */ + OS.VtblCall (18, mTaskbarList3, hwnd, hIcon, 0); + OS.DestroyIcon (hIcon); +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java index 7542a3bf39..45d327c9a3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java @@ -1639,6 +1639,11 @@ public Image getSystemImage (int id) { return null; } +public TaskBar getSystemTaskBar () { + checkDevice (); + return null; +} + /** * Returns the single instance of the system tray or null * when there is no system tray available for the platform. diff --git a/bundles/org.eclipse.swt/buildFragment.xml b/bundles/org.eclipse.swt/buildFragment.xml index e815f9f171..da8aa4d58f 100644 --- a/bundles/org.eclipse.swt/buildFragment.xml +++ b/bundles/org.eclipse.swt/buildFragment.xml @@ -117,6 +117,7 @@ <fileset dir="${plugindir}/Eclipse SWT/emulated/bidi/"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/coolbar/"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/expand/"/> + <fileset dir="${plugindir}/Eclipse SWT/emulated/taskbar/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/common/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/carbon/"/> <fileset dir="${plugindir}/Eclipse SWT AWT/common/"/> @@ -189,6 +190,7 @@ <fileset dir="${plugindir}/Eclipse SWT/common_j2se/" excludes="**/*._properties"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/bidi/"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/coolbar/"/> + <fileset dir="${plugindir}/Eclipse SWT/emulated/taskbar/"/> <fileset dir="${plugindir}/Eclipse SWT/gtk/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/common/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/gtk/"/> @@ -235,6 +237,7 @@ <fileset dir="${plugindir}/Eclipse SWT/emulated/expand"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/tooltip"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/ime"/> + <fileset dir="${plugindir}/Eclipse SWT/emulated/taskbar/"/> <fileset dir="${plugindir}/Eclipse SWT/motif/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/common/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/emulated/"/> @@ -281,6 +284,7 @@ <fileset dir="${plugindir}/Eclipse SWT/emulated/expand/"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/tooltip/"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/ime/"/> + <fileset dir="${plugindir}/Eclipse SWT/emulated/taskbar/"/> <fileset dir="${plugindir}/Eclipse SWT/photon/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/common/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/emulated/"/> @@ -349,6 +353,7 @@ <fileset dir="${plugindir}/Eclipse SWT/emulated/bidi/"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/tooltip/"/> <fileset dir="${plugindir}/Eclipse SWT/emulated/ime/"/> + <fileset dir="${plugindir}/Eclipse SWT/emulated/taskbar/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/common/"/> <fileset dir="${plugindir}/Eclipse SWT Accessibility/emulated/"/> <fileset dir="${plugindir}/Eclipse SWT AWT/common/"/> |