comparison dwt/widgets/Tray.d @ 0:380af2bdd8e5

Upload of whole dwt tree
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sat, 09 Aug 2008 17:00:02 +0200
parents
children 649b8e223d5a 2952d5604c0a
comparison
equal deleted inserted replaced
-1:000000000000 0:380af2bdd8e5
1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 module dwt.widgets.Tray;
12
13 import dwt.dwthelper.utils;
14
15
16 import dwt.DWT;
17 import dwt.DWTException;
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 *
35 * @since 3.0
36 */
37 public class Tray extends Widget {
38 int itemCount;
39 TrayItem [] items = new TrayItem [4];
40
41 Tray (Display display, int style) {
42 if (display is null) display = Display.getCurrent ();
43 if (display is null) display = Display.getDefault ();
44 if (!display.isValidThread ()) {
45 error (DWT.ERROR_THREAD_INVALID_ACCESS);
46 }
47 this.display = display;
48 }
49
50 void createItem (TrayItem item, int index) {
51 if (!(0 <= index && index <= itemCount)) error (DWT.ERROR_INVALID_RANGE);
52 if (itemCount is items.length) {
53 TrayItem [] newItems = new TrayItem [items.length + 4];
54 System.arraycopy (items, 0, newItems, 0, items.length);
55 items = newItems;
56 }
57 System.arraycopy (items, index, items, index + 1, itemCount++ - index);
58 items [index] = item;
59 }
60
61 void destroyItem (TrayItem item) {
62 int index = 0;
63 while (index < itemCount) {
64 if (items [index] is item) break;
65 index++;
66 }
67 if (index is itemCount) return;
68 System.arraycopy (items, index + 1, items, index, --itemCount - index);
69 items [itemCount] = null;
70 }
71
72 /**
73 * Returns the item at the given, zero-relative index in the
74 * receiver. Throws an exception if the index is out of range.
75 *
76 * @param index the index of the item to return
77 * @return the item at the given index
78 *
79 * @exception IllegalArgumentException <ul>
80 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
81 * </ul>
82 * @exception DWTException <ul>
83 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
84 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
85 * </ul>
86 */
87 public TrayItem getItem (int index) {
88 checkWidget ();
89 if (!(0 <= index && index < itemCount)) error (DWT.ERROR_INVALID_RANGE);
90 return items [index];
91 }
92
93 /**
94 * Returns the number of items contained in the receiver.
95 *
96 * @return the number of items
97 *
98 * @exception DWTException <ul>
99 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
100 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
101 * </ul>
102 */
103 public int getItemCount () {
104 checkWidget ();
105 return itemCount;
106 }
107
108 /**
109 * Returns an array of <code>TrayItem</code>s which are the items
110 * in the receiver.
111 * <p>
112 * Note: This is not the actual structure used by the receiver
113 * to maintain its list of items, so modifying the array will
114 * not affect the receiver.
115 * </p>
116 *
117 * @return the items in the receiver
118 *
119 * @exception DWTException <ul>
120 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
121 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
122 * </ul>
123 */
124 public TrayItem [] getItems () {
125 checkWidget ();
126 TrayItem [] result = new TrayItem [itemCount];
127 System.arraycopy (items, 0, result, 0, result.length);
128 return result;
129 }
130
131 void releaseChildren (bool destroy) {
132 if (items !is null) {
133 for (int i=0; i<items.length; i++) {
134 TrayItem item = items [i];
135 if (item !is null && !item.isDisposed ()) {
136 item.release (false);
137 }
138 }
139 items = null;
140 }
141 super.releaseChildren (destroy);
142 }
143
144 void releaseParent () {
145 super.releaseParent ();
146 if (display.tray is this) display.tray = null;
147 }
148
149 }