/******************************************************************************* * 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. * *
*
Styles:
*
(none)
*
Events:
*
(none)
*
* * @see Display#getSystemTaskBar * @see Sample code and further information * * @since 3.6 * * @noextend This class is not intended to be subclassed by clients. */ public class TaskBar extends Widget { int itemCount; TaskItem [] items = new TaskItem [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 (TaskItem item, int index) { if (index == -1) index = itemCount; if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); if (itemCount == items.length) { TaskItem [] newItems = new TaskItem [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 (TaskItem 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 * @exception SWTException */ public TaskItem 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 */ public int getItemCount () { checkWidget (); createItems (); return itemCount; } /** * Returns the TaskItem for the given Shell or the TaskItem * for the application if the Shell parameter is null. * If the requested item is not supported by the platform it returns null. * * @param shell the shell for which the task item is requested, or null to request the application item * @return the task item for the given shell or the application * * @exception SWTException */ public TaskItem getItem (Shell shell) { checkWidget (); for (int i = 0; i < itemCount; i++) { if (items [i] != null && items [i].shell == shell) { return items [i]; } } TaskItem item = null; if (shell == null) { item = new TaskItem (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 TaskItems which are the items * in the receiver. *

* 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. *

* * @return the items in the receiver * * @exception SWTException */ public TaskItem [] getItems () { checkWidget (); createItems (); TaskItem [] result = new TaskItem [itemCount]; System.arraycopy (items, 0, result, 0, result.length); return result; } void releaseChildren (boolean destroy) { if (items != null) { for (int i=0; i