1 /*******************************************************************************
2 * Copyright (c) 2010 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.widgets;
15
16
17 import org.eclipse.swt.*;
18
19 /**
20 * Instances of this class represent the system task bar.
21 *
22 * <dl>
23 * <dt><b>Styles:</b></dt>
24 * <dd>(none)</dd>
25 * <dt><b>Events:</b></dt>
26 * <dd>(none)</dd>
27 * </dl>
28 *
29 * @see Display#getSystemTaskBar
30 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
31 *
32 * @since 3.6
33 *
34 * @noextend This class is not intended to be subclassed by clients.
35 */
36 public class TaskBar extends Widget {
37 int itemCount;
38 TaskItem [] items = new TaskItem [4];
39
TaskBar(Display display, int style)40 TaskBar (Display display, int style) {
41 if (display == null) display = Display.getCurrent ();
42 if (display == null) display = Display.getDefault ();
43 if (!display.isValidThread ()) {
44 error (SWT.ERROR_THREAD_INVALID_ACCESS);
45 }
46 this.display = display;
47 reskinWidget ();
48 }
49
createItem(TaskItem item, int index)50 void createItem (TaskItem item, int index) {
51 if (index == -1) index = itemCount;
52 if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
53 if (itemCount == items.length) {
54 TaskItem [] newItems = new TaskItem [items.length + 4];
55 System.arraycopy (items, 0, newItems, 0, items.length);
56 items = newItems;
57 }
58 System.arraycopy (items, index, items, index + 1, itemCount++ - index);
59 items [index] = item;
60 }
61
createItems()62 void createItems () {
63 }
64
destroyItem(TaskItem item)65 void destroyItem (TaskItem item) {
66 int index = 0;
67 while (index < itemCount) {
68 if (items [index] == item) break;
69 index++;
70 }
71 if (index == itemCount) return;
72 System.arraycopy (items, index + 1, items, index, --itemCount - index);
73 items [itemCount] = null;
74 }
75
76 /**
77 * Returns the item at the given, zero-relative index in the
78 * receiver. Throws an exception if the index is out of range.
79 *
80 * @param index the index of the item to return
81 * @return the item at the given index
82 *
83 * @exception IllegalArgumentException <ul>
84 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
85 * </ul>
86 * @exception SWTException <ul>
87 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
88 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
89 * </ul>
90 */
getItem(int index)91 public TaskItem getItem (int index) {
92 checkWidget ();
93 createItems ();
94 if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
95 return items [index];
96 }
97
98 /**
99 * Returns the number of items contained in the receiver.
100 *
101 * @return the number of items
102 *
103 * @exception SWTException <ul>
104 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
105 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
106 * </ul>
107 */
getItemCount()108 public int getItemCount () {
109 checkWidget ();
110 createItems ();
111 return itemCount;
112 }
113
114 /**
115 * Returns the <code>TaskItem</code> for the given <code>Shell</code> or the <code>TaskItem</code>
116 * for the application if the <code>Shell</code> parameter is <code>null</code>.
117 * If the requested item is not supported by the platform it returns <code>null</code>.
118 *
119 * @param shell the shell for which the task item is requested, or null to request the application item
120 * @return the task item for the given shell or the application
121 *
122 * @exception SWTException <ul>
123 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
124 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
125 * </ul>
126 */
getItem(Shell shell)127 public TaskItem getItem (Shell shell) {
128 checkWidget ();
129 return null;
130 }
131
132 /**
133 * Returns an array of <code>TaskItem</code>s which are the items
134 * in the receiver.
135 * <p>
136 * Note: This is not the actual structure used by the receiver
137 * to maintain its list of items, so modifying the array will
138 * not affect the receiver.
139 * </p>
140 *
141 * @return the items in the receiver
142 *
143 * @exception SWTException <ul>
144 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
145 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
146 * </ul>
147 */
getItems()148 public TaskItem [] getItems () {
149 checkWidget ();
150 createItems ();
151 TaskItem [] result = new TaskItem [itemCount];
152 System.arraycopy (items, 0, result, 0, result.length);
153 return result;
154 }
155
156 @Override
releaseChildren(boolean destroy)157 void releaseChildren (boolean destroy) {
158 if (items != null) {
159 for (TaskItem item : items) {
160 if (item != null && !item.isDisposed ()) {
161 item.release (false);
162 }
163 }
164 items = null;
165 }
166 super.releaseChildren (destroy);
167 }
168
169 @Override
reskinChildren(int flags)170 void reskinChildren (int flags) {
171 if (items != null) {
172 for (TaskItem item : items) {
173 if (item != null) item.reskin (flags);
174 }
175 }
176 super.reskinChildren (flags);
177 }
178
179 }
180