]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/widgets/Tray.java
a0f34b4525ea775bb3af462c746aba2455e7f205
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / widgets / Tray.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2009 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 tray that is part
21  * of the task bar status area on some operating systems.
22  *
23  * <dl>
24  * <dt><b>Styles:</b></dt>
25  * <dd>(none)</dd>
26  * <dt><b>Events:</b></dt>
27  * <dd>(none)</dd>
28  * </dl>
29  * <p>
30  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
31  * </p>
32  *
33  * @see Display#getSystemTray
34  * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
35  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
36  *
37  * @since 3.0
38  * @noextend This class is not intended to be subclassed by clients.
39  */
40 public class Tray extends Widget {
41         int itemCount;
42         TrayItem [] items = new TrayItem [4];
43
44 Tray (Display display, int style) {
45         this.display = display;
46         reskinWidget ();
47 }
48
49 void createItem (TrayItem item, int index) {
50         if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
51         if (itemCount == items.length) {
52                 TrayItem [] newItems = new TrayItem [items.length + 4];
53                 System.arraycopy (items, 0, newItems, 0, items.length);
54                 items = newItems;
55         }
56         System.arraycopy (items, index, items, index + 1, itemCount++ - index);
57         items [index] = item;
58 }
59
60 void destroyItem (TrayItem item) {
61         int index = 0;
62         while (index < itemCount) {
63                 if (items [index] == item) break;
64                 index++;
65         }
66         if (index == itemCount) return;
67         System.arraycopy (items, index + 1, items, index, --itemCount - index);
68         items [itemCount] = null;
69 }
70
71 /**
72  * Returns the item at the given, zero-relative index in the
73  * receiver. Throws an exception if the index is out of range.
74  *
75  * @param index the index of the item to return
76  * @return the item at the given index
77  *
78  * @exception IllegalArgumentException <ul>
79  *    <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
80  * </ul>
81  * @exception SWTException <ul>
82  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
83  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
84  * </ul>
85  */
86 public TrayItem getItem (int index) {
87         checkWidget ();
88         if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
89         return items [index];
90 }
91
92 /**
93  * Returns the number of items contained in the receiver.
94  *
95  * @return the number of items
96  *
97  * @exception SWTException <ul>
98  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
99  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
100  * </ul>
101  */
102 public int getItemCount () {
103         checkWidget ();
104         return itemCount;
105 }
106
107 /**
108  * Returns an array of <code>TrayItem</code>s which are the items
109  * in the receiver.
110  * <p>
111  * Note: This is not the actual structure used by the receiver
112  * to maintain its list of items, so modifying the array will
113  * not affect the receiver.
114  * </p>
115  *
116  * @return the items in the receiver
117  *
118  * @exception SWTException <ul>
119  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
120  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
121  * </ul>
122  */
123 public TrayItem [] getItems () {
124         checkWidget ();
125         TrayItem [] result = new TrayItem [itemCount];
126         System.arraycopy (items, 0, result, 0, result.length);
127         return result;
128 }
129
130 @Override
131 void releaseChildren (boolean destroy) {
132         if (items != null) {
133                 for (int i=0; i<items.length; i++) {
134                         TrayItem item = items [i];
135                         if (item != null && !item.isDisposed ()) {
136                                 item.release (false);
137                         }
138                 }
139                 items = null;
140         }
141         super.releaseChildren (destroy);
142 }
143
144 @Override
145 void releaseParent () {
146         super.releaseParent ();
147         if (display.tray == this) display.tray = null;
148 }
149
150 @Override
151 void reskinChildren (int flags) {
152         if (items != null) {
153                 for (int i=0; i<items.length; i++) {
154                         TrayItem item = items [i];
155                         if (item != null) item.reskin (flags);
156                 }
157         }
158         super.reskinChildren (flags);
159 }
160
161 }