Mercurial > projects > dwt-mac
comparison dwt/widgets/TableItem.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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2007 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.TableItem; | |
12 | |
13 import dwt.dwthelper.utils; | |
14 | |
15 | |
16 import dwt.DWT; | |
17 import dwt.DWTException; | |
18 import dwt.graphics.Color; | |
19 import dwt.graphics.Font; | |
20 import dwt.graphics.GC; | |
21 import dwt.graphics.Image; | |
22 import dwt.graphics.Rectangle; | |
23 import dwt.internal.cocoa.NSAttributedString; | |
24 import dwt.internal.cocoa.NSColor; | |
25 import dwt.internal.cocoa.NSMutableDictionary; | |
26 import dwt.internal.cocoa.NSRect; | |
27 import dwt.internal.cocoa.NSString; | |
28 import dwt.internal.cocoa.NSTableView; | |
29 import dwt.internal.cocoa.OS; | |
30 | |
31 /** | |
32 * Instances of this class represent a selectable user interface object | |
33 * that represents an item in a table. | |
34 * <dl> | |
35 * <dt><b>Styles:</b></dt> | |
36 * <dd>(none)</dd> | |
37 * <dt><b>Events:</b></dt> | |
38 * <dd>(none)</dd> | |
39 * </dl> | |
40 * <p> | |
41 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
42 * </p> | |
43 */ | |
44 public class TableItem extends Item { | |
45 Table parent; | |
46 String [] strings; | |
47 Image [] images; | |
48 bool checked, grayed, cached; | |
49 Color foreground, background; | |
50 Color[] cellForeground, cellBackground; | |
51 Font font; | |
52 Font[] cellFont; | |
53 int width = -1; | |
54 | |
55 /** | |
56 * Constructs a new instance of this class given its parent | |
57 * (which must be a <code>Table</code>) and a style value | |
58 * describing its behavior and appearance. The item is added | |
59 * to the end of the items maintained by its parent. | |
60 * <p> | |
61 * The style value is either one of the style constants defined in | |
62 * class <code>DWT</code> which is applicable to instances of this | |
63 * class, or must be built by <em>bitwise OR</em>'ing together | |
64 * (that is, using the <code>int</code> "|" operator) two or more | |
65 * of those <code>DWT</code> style constants. The class description | |
66 * lists the style constants that are applicable to the class. | |
67 * Style bits are also inherited from superclasses. | |
68 * </p> | |
69 * | |
70 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
71 * @param style the style of control to construct | |
72 * | |
73 * @exception IllegalArgumentException <ul> | |
74 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
75 * </ul> | |
76 * @exception DWTException <ul> | |
77 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
78 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
79 * </ul> | |
80 * | |
81 * @see DWT | |
82 * @see Widget#checkSubclass | |
83 * @see Widget#getStyle | |
84 */ | |
85 public TableItem (Table parent, int style) { | |
86 this (parent, style, checkNull (parent).getItemCount (), true); | |
87 } | |
88 | |
89 /** | |
90 * Constructs a new instance of this class given its parent | |
91 * (which must be a <code>Table</code>), a style value | |
92 * describing its behavior and appearance, and the index | |
93 * at which to place it in the items maintained by its parent. | |
94 * <p> | |
95 * The style value is either one of the style constants defined in | |
96 * class <code>DWT</code> which is applicable to instances of this | |
97 * class, or must be built by <em>bitwise OR</em>'ing together | |
98 * (that is, using the <code>int</code> "|" operator) two or more | |
99 * of those <code>DWT</code> style constants. The class description | |
100 * lists the style constants that are applicable to the class. | |
101 * Style bits are also inherited from superclasses. | |
102 * </p> | |
103 * | |
104 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
105 * @param style the style of control to construct | |
106 * @param index the zero-relative index to store the receiver in its parent | |
107 * | |
108 * @exception IllegalArgumentException <ul> | |
109 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
110 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> | |
111 * </ul> | |
112 * @exception DWTException <ul> | |
113 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
114 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
115 * </ul> | |
116 * | |
117 * @see DWT | |
118 * @see Widget#checkSubclass | |
119 * @see Widget#getStyle | |
120 */ | |
121 public TableItem (Table parent, int style, int index) { | |
122 this (parent, style, index, true); | |
123 } | |
124 | |
125 TableItem (Table parent, int style, int index, bool create) { | |
126 super (parent, style); | |
127 this.parent = parent; | |
128 if (create) parent.createItem (this, index); | |
129 } | |
130 | |
131 static Table checkNull (Table control) { | |
132 if (control is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
133 return control; | |
134 } | |
135 | |
136 int calculateWidth (int index, GC gc) { | |
137 if (index is 0 && width !is -1) return width; | |
138 int width = 0; | |
139 Image image = getImage (index); | |
140 String text = getText (index); | |
141 gc.setFont (getFont (index)); | |
142 // if (image !is null) width += image.getBounds ().width + parent.getGap (); | |
143 if (text !is null && text.length () > 0) width += gc.stringExtent (text).x; | |
144 // if (parent.hooks (DWT.MeasureItem)) { | |
145 // Event event = new Event (); | |
146 // event.item = this; | |
147 // event.index = index; | |
148 // event.gc = gc; | |
149 // short [] height = new short [1]; | |
150 // OS.GetDataBrowserTableViewRowHeight (parent.handle, height); | |
151 // event.width = width; | |
152 // event.height = height[0]; | |
153 // parent.sendEvent (DWT.MeasureItem, event); | |
154 // if (parent.itemHeight < event.height) { | |
155 // parent.itemHeight = event.height; | |
156 // OS.SetDataBrowserTableViewRowHeight (parent.handle, (short) event.height); | |
157 // } | |
158 // width = event.width; | |
159 // } | |
160 if (index is 0) this.width = width; | |
161 return width; | |
162 } | |
163 | |
164 protected void checkSubclass () { | |
165 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); | |
166 } | |
167 | |
168 void clear () { | |
169 text = ""; | |
170 image = null; | |
171 strings = null; | |
172 images = null; | |
173 checked = grayed = cached = false; | |
174 foreground = background = null; | |
175 cellForeground = cellBackground = null; | |
176 font = null; | |
177 cellFont = null; | |
178 width = -1; | |
179 } | |
180 | |
181 NSAttributedString createString(int index) { | |
182 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); | |
183 Color foreground = cellForeground !is null ? cellForeground [index] : null; | |
184 if (foreground is null) foreground = this.foreground; | |
185 if (foreground is null) foreground = parent.foreground; | |
186 if (foreground !is null) { | |
187 NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1); | |
188 dict.setObject(color, OS.NSForegroundColorAttributeName()); | |
189 } | |
190 Font font = cellFont !is null ? cellFont [index] : null; | |
191 if (font is null) font = this.font; | |
192 // if (font is null) font = parent.font; | |
193 if (font !is null) { | |
194 dict.setObject(font.handle, OS.NSFontAttributeName()); | |
195 } | |
196 Color background = cellBackground !is null ? cellBackground [index] : null; | |
197 if (background is null) background = this.background; | |
198 if (background !is null) { | |
199 NSColor color = NSColor.colorWithDeviceRed(background.handle[0], background.handle[1], background.handle[2], 1); | |
200 dict.setObject(color, OS.NSBackgroundColorAttributeName()); | |
201 } | |
202 String text = getText (index); | |
203 int length = text.length(); | |
204 char[] chars = new char[length]; | |
205 text.getChars(0, length, chars, 0); | |
206 NSString str = NSString.stringWithCharacters(chars, length); | |
207 NSAttributedString attribStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict); | |
208 attribStr.autorelease(); | |
209 return attribStr; | |
210 } | |
211 | |
212 void destroyWidget () { | |
213 parent.destroyItem (this); | |
214 releaseHandle (); | |
215 } | |
216 | |
217 /** | |
218 * Returns the receiver's background color. | |
219 * | |
220 * @return the background color | |
221 * | |
222 * @exception DWTException <ul> | |
223 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
224 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
225 * </ul> | |
226 * | |
227 * @since 2.0 | |
228 */ | |
229 public Color getBackground () { | |
230 checkWidget (); | |
231 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
232 return background !is null ? background : parent.getBackground (); | |
233 } | |
234 | |
235 /** | |
236 * Returns the background color at the given column index in the receiver. | |
237 * | |
238 * @param index the column index | |
239 * @return the background color | |
240 * | |
241 * @exception DWTException <ul> | |
242 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
243 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
244 * </ul> | |
245 * | |
246 * @since 3.0 | |
247 */ | |
248 public Color getBackground (int index) { | |
249 checkWidget (); | |
250 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
251 int count = Math.max (1, parent.columnCount); | |
252 if (0 > index || index > count -1) return getBackground (); | |
253 if (cellBackground is null || cellBackground [index] is null) return getBackground (); | |
254 return cellBackground [index]; | |
255 } | |
256 | |
257 /** | |
258 * Returns a rectangle describing the receiver's size and location | |
259 * relative to its parent. | |
260 * | |
261 * @return the receiver's bounding rectangle | |
262 * | |
263 * @exception DWTException <ul> | |
264 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
265 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
266 * </ul> | |
267 * | |
268 * @since 3.2 | |
269 */ | |
270 public Rectangle getBounds () { | |
271 checkWidget (); | |
272 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
273 NSTableView tableView = (NSTableView) parent.view; | |
274 NSRect rect = tableView.rectOfRow (parent.indexOf (this)); | |
275 rect = tableView.convertRect_toView_ (rect, parent.scrollView); | |
276 Rectangle result = new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height); | |
277 return result; | |
278 } | |
279 | |
280 /** | |
281 * Returns a rectangle describing the receiver's size and location | |
282 * relative to its parent at a column in the table. | |
283 * | |
284 * @param index the index that specifies the column | |
285 * @return the receiver's bounding column rectangle | |
286 * | |
287 * @exception DWTException <ul> | |
288 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
289 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
290 * </ul> | |
291 */ | |
292 public Rectangle getBounds (int index) { | |
293 checkWidget (); | |
294 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
295 NSTableView tableView = (NSTableView) parent.view; | |
296 if ((parent.style & DWT.CHECK) !is 0) index ++; | |
297 NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this)); | |
298 rect = tableView.convertRect_toView_ (rect, parent.scrollView); | |
299 Rectangle result = new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height); | |
300 return result; | |
301 } | |
302 | |
303 /** | |
304 * Returns <code>true</code> if the receiver is checked, | |
305 * and false otherwise. When the parent does not have | |
306 * the <code>CHECK</code> style, return false. | |
307 * | |
308 * @return the checked state of the checkbox | |
309 * | |
310 * @exception DWTException <ul> | |
311 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
312 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
313 * </ul> | |
314 */ | |
315 public bool getChecked () { | |
316 checkWidget (); | |
317 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
318 if ((parent.style & DWT.CHECK) is 0) return false; | |
319 return checked; | |
320 } | |
321 | |
322 /** | |
323 * Returns the font that the receiver will use to paint textual information for this item. | |
324 * | |
325 * @return the receiver's font | |
326 * | |
327 * @exception DWTException <ul> | |
328 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
329 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
330 * </ul> | |
331 * | |
332 * @since 3.0 | |
333 */ | |
334 public Font getFont () { | |
335 checkWidget (); | |
336 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
337 return font !is null ? font : parent.getFont (); | |
338 } | |
339 | |
340 /** | |
341 * Returns the font that the receiver will use to paint textual information | |
342 * for the specified cell in this item. | |
343 * | |
344 * @param index the column index | |
345 * @return the receiver's font | |
346 * | |
347 * @exception DWTException <ul> | |
348 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
349 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
350 * </ul> | |
351 * | |
352 * @since 3.0 | |
353 */ | |
354 public Font getFont (int index) { | |
355 checkWidget (); | |
356 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
357 int count = Math.max (1, parent.columnCount); | |
358 if (0 > index || index > count -1) return getFont (); | |
359 if (cellFont is null || cellFont [index] is null) return getFont (); | |
360 return cellFont [index]; | |
361 } | |
362 | |
363 /** | |
364 * Returns the foreground color that the receiver will use to draw. | |
365 * | |
366 * @return the receiver's foreground color | |
367 * | |
368 * @exception DWTException <ul> | |
369 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
370 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
371 * </ul> | |
372 * | |
373 * @since 2.0 | |
374 */ | |
375 public Color getForeground () { | |
376 checkWidget (); | |
377 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
378 return foreground !is null ? foreground : parent.getForeground (); | |
379 } | |
380 | |
381 /** | |
382 * | |
383 * Returns the foreground color at the given column index in the receiver. | |
384 * | |
385 * @param index the column index | |
386 * @return the foreground color | |
387 * | |
388 * @exception DWTException <ul> | |
389 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
390 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
391 * </ul> | |
392 * | |
393 * @since 3.0 | |
394 */ | |
395 public Color getForeground (int index) { | |
396 checkWidget (); | |
397 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
398 int count = Math.max (1, parent.columnCount); | |
399 if (0 > index || index > count -1) return getForeground (); | |
400 if (cellForeground is null || cellForeground [index] is null) return getForeground (); | |
401 return cellForeground [index]; | |
402 } | |
403 | |
404 /** | |
405 * Returns <code>true</code> if the receiver is grayed, | |
406 * and false otherwise. When the parent does not have | |
407 * the <code>CHECK</code> style, return false. | |
408 * | |
409 * @return the grayed state of the checkbox | |
410 * | |
411 * @exception DWTException <ul> | |
412 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
413 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
414 * </ul> | |
415 */ | |
416 public bool getGrayed () { | |
417 checkWidget (); | |
418 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
419 if ((parent.style & DWT.CHECK) is 0) return false; | |
420 return grayed; | |
421 } | |
422 | |
423 public Image getImage () { | |
424 checkWidget(); | |
425 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
426 return super.getImage (); | |
427 } | |
428 | |
429 /** | |
430 * Returns the image stored at the given column index in the receiver, | |
431 * or null if the image has not been set or if the column does not exist. | |
432 * | |
433 * @param index the column index | |
434 * @return the image stored at the given column index in the receiver | |
435 * | |
436 * @exception DWTException <ul> | |
437 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
438 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
439 * </ul> | |
440 */ | |
441 public Image getImage (int index) { | |
442 checkWidget(); | |
443 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
444 if (index is 0) return getImage (); | |
445 if (images !is null) { | |
446 if (0 <= index && index < images.length) return images [index]; | |
447 } | |
448 return null; | |
449 } | |
450 | |
451 /** | |
452 * Returns a rectangle describing the size and location | |
453 * relative to its parent of an image at a column in the | |
454 * table. An empty rectangle is returned if index exceeds | |
455 * the index of the table's last column. | |
456 * | |
457 * @param index the index that specifies the column | |
458 * @return the receiver's bounding image rectangle | |
459 * | |
460 * @exception DWTException <ul> | |
461 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
462 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
463 * </ul> | |
464 */ | |
465 public Rectangle getImageBounds (int index) { | |
466 checkWidget(); | |
467 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
468 // parent.checkItems (true); | |
469 // if (index !is 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0); | |
470 // Rect rect = new Rect(); | |
471 // int itemIndex = parent.indexOf (this); | |
472 // int id = itemIndex + 1; | |
473 // int columnId = parent.columnCount is 0 ? parent.column_id : parent.columns [index].id; | |
474 // if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect) !is OS.noErr) { | |
475 // return new Rectangle (0, 0, 0, 0); | |
476 // } | |
477 // int x = rect.left, y = rect.top; | |
478 // int width = 0; | |
479 // if (index is 0 && image !is null) { | |
480 // Rectangle bounds = image.getBounds (); | |
481 // width += bounds.width; | |
482 // } | |
483 // if (index !is 0 && images !is null && images[index] !is null) { | |
484 // Rectangle bounds = images [index].getBounds (); | |
485 // width += bounds.width; | |
486 // } | |
487 // int height = rect.bottom - rect.top + 1; | |
488 // return new Rectangle (x, y, width, height); | |
489 return null; | |
490 } | |
491 | |
492 /** | |
493 * Gets the image indent. | |
494 * | |
495 * @return the indent | |
496 * | |
497 * @exception DWTException <ul> | |
498 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
499 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
500 * </ul> | |
501 */ | |
502 public int getImageIndent () { | |
503 checkWidget(); | |
504 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
505 return 0; | |
506 } | |
507 | |
508 String getNameText () { | |
509 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
510 if (!cached) return "*virtual*"; //$NON-NLS-1$ | |
511 } | |
512 return super.getNameText (); | |
513 } | |
514 | |
515 /** | |
516 * Returns the receiver's parent, which must be a <code>Table</code>. | |
517 * | |
518 * @return the receiver's parent | |
519 * | |
520 * @exception DWTException <ul> | |
521 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
522 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
523 * </ul> | |
524 */ | |
525 public Table getParent () { | |
526 checkWidget (); | |
527 return parent; | |
528 } | |
529 | |
530 public String getText () { | |
531 checkWidget (); | |
532 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
533 return super.getText (); | |
534 } | |
535 | |
536 /** | |
537 * Returns the text stored at the given column index in the receiver, | |
538 * or empty string if the text has not been set. | |
539 * | |
540 * @param index the column index | |
541 * @return the text stored at the given column index in the receiver | |
542 * | |
543 * @exception DWTException <ul> | |
544 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
545 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
546 * </ul> | |
547 */ | |
548 public String getText (int index) { | |
549 checkWidget (); | |
550 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
551 if (index is 0) return getText (); | |
552 if (strings !is null) { | |
553 if (0 <= index && index < strings.length) { | |
554 String string = strings [index]; | |
555 return string !is null ? string : ""; | |
556 } | |
557 } | |
558 return ""; | |
559 } | |
560 | |
561 /** | |
562 * Returns a rectangle describing the size and location | |
563 * relative to its parent of the text at a column in the | |
564 * table. An empty rectangle is returned if index exceeds | |
565 * the index of the table's last column. | |
566 * | |
567 * @param index the index that specifies the column | |
568 * @return the receiver's bounding text rectangle | |
569 * | |
570 * @exception DWTException <ul> | |
571 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
572 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
573 * </ul> | |
574 * | |
575 * @since 3.3 | |
576 */ | |
577 public Rectangle getTextBounds (int index) { | |
578 checkWidget (); | |
579 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
580 // parent.checkItems (true); | |
581 // if (index !is 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0); | |
582 // Rect rect = new Rect(); | |
583 // int itemIndex = parent.indexOf (this); | |
584 // int id = itemIndex + 1; | |
585 // int columnId = parent.columnCount is 0 ? parent.column_id : parent.columns [index].id; | |
586 // if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) !is OS.noErr) { | |
587 // return new Rectangle (0, 0, 0, 0); | |
588 // } | |
589 // int imageWidth = 0; | |
590 // int margin = parent.getInsetWidth () / 2; | |
591 // Image image = getImage (index); | |
592 // if (image !is null) { | |
593 // Rectangle bounds = image.getBounds (); | |
594 // imageWidth = bounds.width + parent.getGap (); | |
595 // } | |
596 // int x, y, width, height; | |
597 // if (OS.VERSION >= 0x1040) { | |
598 // if (parent.getLinesVisible ()) { | |
599 // rect.left += Table.GRID_WIDTH; | |
600 // rect.top += Table.GRID_WIDTH; | |
601 // } | |
602 // x = rect.left + imageWidth + margin; | |
603 // y = rect.top; | |
604 // width = Math.max (0, rect.right - rect.left - imageWidth - margin * 2); | |
605 // height = rect.bottom - rect.top; | |
606 // } else { | |
607 // Rect rect2 = new Rect(); | |
608 // if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect2) !is OS.noErr) { | |
609 // return new Rectangle (0, 0, 0, 0); | |
610 // } | |
611 // x = rect2.left + imageWidth + margin; | |
612 // y = rect2.top; | |
613 // width = Math.max (0, rect.right - rect2.left + 1 - imageWidth - margin * 2); | |
614 // height = rect2.bottom - rect2.top + 1; | |
615 // } | |
616 // return new Rectangle (x, y, width, height); | |
617 return null; | |
618 } | |
619 | |
620 void redraw () { | |
621 // 0[aTableView setNeedsDisplayInRect:[aTableView rectOfRow:row]]; | |
622 ((NSTableView)parent.view).reloadData(); | |
623 ((NSTableView)parent.view).tile(); | |
624 } | |
625 | |
626 void releaseHandle () { | |
627 super.releaseHandle (); | |
628 parent = null; | |
629 } | |
630 | |
631 void releaseParent () { | |
632 super.releaseParent (); | |
633 // parent.checkItems (true); | |
634 } | |
635 | |
636 void releaseWidget () { | |
637 super.releaseWidget (); | |
638 strings = null; | |
639 images = null; | |
640 background = foreground = null; | |
641 font = null; | |
642 cellBackground = cellForeground = null; | |
643 cellFont = null; | |
644 } | |
645 | |
646 /** | |
647 * Sets the receiver's background color to the color specified | |
648 * by the argument, or to the default system color for the item | |
649 * if the argument is null. | |
650 * | |
651 * @param color the new color (or null) | |
652 * | |
653 * @exception IllegalArgumentException <ul> | |
654 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
655 * </ul> | |
656 * @exception DWTException <ul> | |
657 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
658 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
659 * </ul> | |
660 * | |
661 * @since 2.0 | |
662 */ | |
663 public void setBackground (Color color) { | |
664 checkWidget (); | |
665 if (color !is null && color.isDisposed ()) { | |
666 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
667 } | |
668 Color oldColor = background; | |
669 if (oldColor is color) return; | |
670 background = color; | |
671 if (oldColor !is null && oldColor.equals (color)) return; | |
672 cached = true; | |
673 NSTableView view = (NSTableView)parent.view; | |
674 NSRect rect = view.rectOfRow(parent.indexOf(this)); | |
675 view.setNeedsDisplayInRect(rect); | |
676 } | |
677 | |
678 /** | |
679 * Sets the background color at the given column index in the receiver | |
680 * to the color specified by the argument, or to the default system color for the item | |
681 * if the argument is null. | |
682 * | |
683 * @param index the column index | |
684 * @param color the new color (or null) | |
685 * | |
686 * @exception IllegalArgumentException <ul> | |
687 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
688 * </ul> | |
689 * @exception DWTException <ul> | |
690 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
691 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
692 * </ul> | |
693 * | |
694 * @since 3.0 | |
695 */ | |
696 public void setBackground (int index, Color color) { | |
697 checkWidget (); | |
698 if (color !is null && color.isDisposed ()) { | |
699 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
700 } | |
701 int count = Math.max (1, parent.columnCount); | |
702 if (0 > index || index > count - 1) return; | |
703 if (cellBackground is null) { | |
704 if (color is null) return; | |
705 cellBackground = new Color [count]; | |
706 } | |
707 Color oldColor = cellBackground [index]; | |
708 if (oldColor is color) return; | |
709 cellBackground [index] = color; | |
710 if (oldColor !is null && oldColor.equals (color)) return; | |
711 cached = true; | |
712 NSTableView view = (NSTableView)parent.view; | |
713 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); | |
714 view.setNeedsDisplayInRect(rect); | |
715 } | |
716 | |
717 /** | |
718 * Sets the checked state of the checkbox for this item. This state change | |
719 * only applies if the Table was created with the DWT.CHECK style. | |
720 * | |
721 * @param checked the new checked state of the checkbox | |
722 * | |
723 * @exception DWTException <ul> | |
724 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
725 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
726 * </ul> | |
727 */ | |
728 public void setChecked (bool checked) { | |
729 checkWidget (); | |
730 if ((parent.style & DWT.CHECK) is 0) return; | |
731 if (this.checked is checked) return; | |
732 this.checked = checked; | |
733 cached = true; | |
734 NSTableView view = (NSTableView)parent.view; | |
735 NSRect rect = view.rectOfRow(parent.indexOf(this)); | |
736 view.setNeedsDisplayInRect(rect); | |
737 } | |
738 | |
739 /** | |
740 * Sets the font that the receiver will use to paint textual information | |
741 * for this item to the font specified by the argument, or to the default font | |
742 * for that kind of control if the argument is null. | |
743 * | |
744 * @param font the new font (or null) | |
745 * | |
746 * @exception IllegalArgumentException <ul> | |
747 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
748 * </ul> | |
749 * @exception DWTException <ul> | |
750 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
751 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
752 * </ul> | |
753 * | |
754 * @since 3.0 | |
755 */ | |
756 public void setFont (Font font) { | |
757 checkWidget (); | |
758 if (font !is null && font.isDisposed ()) { | |
759 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
760 } | |
761 Font oldFont = this.font; | |
762 if (oldFont is font) return; | |
763 this.font = font; | |
764 if (oldFont !is null && oldFont.equals (font)) return; | |
765 cached = true; | |
766 NSTableView view = (NSTableView)parent.view; | |
767 NSRect rect = view.rectOfRow(parent.indexOf(this)); | |
768 view.setNeedsDisplayInRect(rect); | |
769 } | |
770 | |
771 /** | |
772 * Sets the font that the receiver will use to paint textual information | |
773 * for the specified cell in this item to the font specified by the | |
774 * argument, or to the default font for that kind of control if the | |
775 * argument is null. | |
776 * | |
777 * @param index the column index | |
778 * @param font the new font (or null) | |
779 * | |
780 * @exception IllegalArgumentException <ul> | |
781 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
782 * </ul> | |
783 * @exception DWTException <ul> | |
784 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
785 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
786 * </ul> | |
787 * | |
788 * @since 3.0 | |
789 */ | |
790 public void setFont (int index, Font font) { | |
791 checkWidget (); | |
792 if (font !is null && font.isDisposed ()) { | |
793 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
794 } | |
795 int count = Math.max (1, parent.columnCount); | |
796 if (0 > index || index > count - 1) return; | |
797 if (cellFont is null) { | |
798 if (font is null) return; | |
799 cellFont = new Font [count]; | |
800 } | |
801 Font oldFont = cellFont [index]; | |
802 if (oldFont is font) return; | |
803 cellFont [index] = font; | |
804 if (oldFont !is null && oldFont.equals (font)) return; | |
805 cached = true; | |
806 NSTableView view = (NSTableView)parent.view; | |
807 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); | |
808 view.setNeedsDisplayInRect(rect); | |
809 } | |
810 | |
811 /** | |
812 * Sets the receiver's foreground color to the color specified | |
813 * by the argument, or to the default system color for the item | |
814 * if the argument is null. | |
815 * | |
816 * @param color the new color (or null) | |
817 * | |
818 * @exception IllegalArgumentException <ul> | |
819 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
820 * </ul> | |
821 * @exception DWTException <ul> | |
822 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
823 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
824 * </ul> | |
825 * | |
826 * @since 2.0 | |
827 */ | |
828 public void setForeground (Color color) { | |
829 checkWidget (); | |
830 if (color !is null && color.isDisposed ()) { | |
831 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
832 } | |
833 Color oldColor = foreground; | |
834 if (oldColor is color) return; | |
835 foreground = color; | |
836 if (oldColor !is null && oldColor.equals (color)) return; | |
837 cached = true; | |
838 NSTableView view = (NSTableView)parent.view; | |
839 NSRect rect = view.rectOfRow(parent.indexOf(this)); | |
840 view.setNeedsDisplayInRect(rect); | |
841 } | |
842 | |
843 /** | |
844 * Sets the foreground color at the given column index in the receiver | |
845 * to the color specified by the argument, or to the default system color for the item | |
846 * if the argument is null. | |
847 * | |
848 * @param index the column index | |
849 * @param color the new color (or null) | |
850 * | |
851 * @exception IllegalArgumentException <ul> | |
852 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
853 * </ul> | |
854 * @exception DWTException <ul> | |
855 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
856 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
857 * </ul> | |
858 * | |
859 * @since 3.0 | |
860 */ | |
861 public void setForeground (int index, Color color){ | |
862 checkWidget (); | |
863 if (color !is null && color.isDisposed ()) { | |
864 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
865 } | |
866 int count = Math.max (1, parent.columnCount); | |
867 if (0 > index || index > count - 1) return; | |
868 if (cellForeground is null) { | |
869 if (color is null) return; | |
870 cellForeground = new Color [count]; | |
871 } | |
872 Color oldColor = cellForeground [index]; | |
873 if (oldColor is color) return; | |
874 cellForeground [index] = color; | |
875 if (oldColor !is null && oldColor.equals (color)) return; | |
876 cached = true; | |
877 NSTableView view = (NSTableView)parent.view; | |
878 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); | |
879 view.setNeedsDisplayInRect(rect); | |
880 } | |
881 | |
882 /** | |
883 * Sets the grayed state of the checkbox for this item. This state change | |
884 * only applies if the Table was created with the DWT.CHECK style. | |
885 * | |
886 * @param grayed the new grayed state of the checkbox; | |
887 * | |
888 * @exception DWTException <ul> | |
889 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
890 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
891 * </ul> | |
892 */ | |
893 public void setGrayed (bool grayed) { | |
894 checkWidget (); | |
895 if ((parent.style & DWT.CHECK) is 0) return; | |
896 if (this.grayed is grayed) return; | |
897 this.grayed = grayed; | |
898 cached = true; | |
899 NSTableView view = (NSTableView)parent.view; | |
900 NSRect rect = view.rectOfRow(parent.indexOf(this)); | |
901 view.setNeedsDisplayInRect(rect); | |
902 } | |
903 | |
904 /** | |
905 * Sets the image for multiple columns in the table. | |
906 * | |
907 * @param images the array of new images | |
908 * | |
909 * @exception IllegalArgumentException <ul> | |
910 * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li> | |
911 * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li> | |
912 * </ul> | |
913 * @exception DWTException <ul> | |
914 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
915 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
916 * </ul> | |
917 */ | |
918 public void setImage (Image [] images) { | |
919 checkWidget(); | |
920 if (images is null) error (DWT.ERROR_NULL_ARGUMENT); | |
921 for (int i=0; i<images.length; i++) { | |
922 setImage (i, images [i]); | |
923 } | |
924 } | |
925 | |
926 /** | |
927 * Sets the receiver's image at a column. | |
928 * | |
929 * @param index the column index | |
930 * @param image the new image | |
931 * | |
932 * @exception IllegalArgumentException <ul> | |
933 * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> | |
934 * </ul> | |
935 * @exception DWTException <ul> | |
936 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
937 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
938 * </ul> | |
939 */ | |
940 public void setImage (int index, Image image) { | |
941 checkWidget(); | |
942 if (image !is null && image.isDisposed ()) { | |
943 error(DWT.ERROR_INVALID_ARGUMENT); | |
944 } | |
945 int itemIndex = parent.indexOf (this); | |
946 if (itemIndex is -1) return; | |
947 // if (parent.imageBounds is null && image !is null) { | |
948 // parent.setItemHeight (image); | |
949 // } | |
950 if (index is 0) { | |
951 if (image !is null && image.type is DWT.ICON) { | |
952 if (image.equals (this.image)) return; | |
953 } | |
954 width = -1; | |
955 super.setImage (image); | |
956 } | |
957 int count = Math.max (1, parent.columnCount); | |
958 if (0 <= index && index < count) { | |
959 if (images is null) images = new Image [count]; | |
960 if (image !is null && image.type is DWT.ICON) { | |
961 if (image.equals (images [index])) return; | |
962 } | |
963 images [index] = image; | |
964 } | |
965 // cached = true; | |
966 // if (index is 0) parent.setScrollWidth (this); | |
967 NSTableView view = (NSTableView)parent.view; | |
968 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); | |
969 view.setNeedsDisplayInRect(rect); | |
970 } | |
971 | |
972 public void setImage (Image image) { | |
973 checkWidget (); | |
974 setImage (0, image); | |
975 } | |
976 | |
977 /** | |
978 * Sets the indent of the first column's image, expressed in terms of the image's width. | |
979 * | |
980 * @param indent the new indent | |
981 * | |
982 * </ul> | |
983 * @exception DWTException <ul> | |
984 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
985 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
986 * </ul> | |
987 * | |
988 * @deprecated this functionality is not supported on most platforms | |
989 */ | |
990 public void setImageIndent (int indent) { | |
991 checkWidget(); | |
992 if (indent < 0) return; | |
993 cached = true; | |
994 /* Image indent is not supported on the Macintosh */ | |
995 } | |
996 | |
997 /** | |
998 * Sets the text for multiple columns in the table. | |
999 * | |
1000 * @param strings the array of new strings | |
1001 * | |
1002 * @exception IllegalArgumentException <ul> | |
1003 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
1004 * </ul> | |
1005 * @exception DWTException <ul> | |
1006 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1007 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1008 * </ul> | |
1009 */ | |
1010 public void setText (String [] strings) { | |
1011 checkWidget(); | |
1012 if (strings is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1013 for (int i=0; i<strings.length; i++) { | |
1014 String string = strings [i]; | |
1015 if (string !is null) setText (i, string); | |
1016 } | |
1017 } | |
1018 | |
1019 /** | |
1020 * Sets the receiver's text at a column | |
1021 * | |
1022 * @param index the column index | |
1023 * @param string the new text | |
1024 * | |
1025 * @exception IllegalArgumentException <ul> | |
1026 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
1027 * </ul> | |
1028 * @exception DWTException <ul> | |
1029 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1030 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1031 * </ul> | |
1032 */ | |
1033 public void setText (int index, String string) { | |
1034 checkWidget(); | |
1035 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1036 if (index is 0) { | |
1037 if (string.equals (text)) return; | |
1038 width = -1; | |
1039 super.setText (string); | |
1040 } | |
1041 int count = Math.max (1, parent.columnCount); | |
1042 if (0 <= index && index < count) { | |
1043 if (strings is null) strings = new String [count]; | |
1044 if (string.equals (strings [index])) return; | |
1045 strings [index] = string; | |
1046 } | |
1047 cached = true; | |
1048 if (index is 0) parent.setScrollWidth (this); | |
1049 NSTableView view = (NSTableView)parent.view; | |
1050 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); | |
1051 view.setNeedsDisplayInRect(rect); | |
1052 } | |
1053 | |
1054 public void setText (String string) { | |
1055 checkWidget(); | |
1056 setText (0, string); | |
1057 } | |
1058 | |
1059 } |