Mercurial > projects > dwt-mac
comparison dwt/widgets/Tree.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | e831403a80a9 |
children | cfa563df4fdd |
comparison
equal
deleted
inserted
replaced
44:ca5e494f2bbf | 45:d8635bb48c7c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
10 *******************************************************************************/ | 10 *******************************************************************************/ |
11 module dwt.widgets.Tree; | 11 module dwt.widgets.Tree; |
12 | 12 |
13 import dwt.dwthelper.utils; | 13 import dwt.dwthelper.utils; |
14 | 14 |
15 | |
16 import dwt.DWT; | 15 import dwt.DWT; |
17 import dwt.DWTException; | 16 import dwt.DWTException; |
17 import dwt.accessibility.ACC; | |
18 import dwt.events.SelectionEvent; | 18 import dwt.events.SelectionEvent; |
19 import dwt.events.SelectionListener; | 19 import dwt.events.SelectionListener; |
20 import dwt.events.TreeListener; | 20 import dwt.events.TreeListener; |
21 import dwt.graphics.Color; | 21 import dwt.graphics.Color; |
22 import dwt.graphics.Font; | 22 import dwt.graphics.Font; |
23 import dwt.graphics.GC; | |
24 import dwt.graphics.GCData; | |
23 import dwt.graphics.Image; | 25 import dwt.graphics.Image; |
24 import dwt.graphics.Point; | 26 import dwt.graphics.Point; |
25 import dwt.graphics.Rectangle; | 27 import dwt.graphics.Rectangle; |
28 import dwt.internal.cocoa.NSArray; | |
29 import dwt.internal.cocoa.NSBezierPath; | |
26 import dwt.internal.cocoa.NSBrowserCell; | 30 import dwt.internal.cocoa.NSBrowserCell; |
27 import dwt.internal.cocoa.NSButtonCell; | 31 import dwt.internal.cocoa.NSButtonCell; |
32 import dwt.internal.cocoa.NSColor; | |
33 import dwt.internal.cocoa.NSColorSpace; | |
34 import dwt.internal.cocoa.NSDictionary; | |
35 import dwt.internal.cocoa.NSEvent; | |
36 import dwt.internal.cocoa.NSFont; | |
37 import dwt.internal.cocoa.NSGraphicsContext; | |
28 import dwt.internal.cocoa.NSIndexSet; | 38 import dwt.internal.cocoa.NSIndexSet; |
39 import dwt.internal.cocoa.NSMutableIndexSet; | |
40 import dwt.internal.cocoa.NSNotification; | |
29 import dwt.internal.cocoa.NSNumber; | 41 import dwt.internal.cocoa.NSNumber; |
30 import dwt.internal.cocoa.NSOutlineView; | 42 import dwt.internal.cocoa.NSOutlineView; |
43 import dwt.internal.cocoa.NSPoint; | |
44 import dwt.internal.cocoa.NSRange; | |
31 import dwt.internal.cocoa.NSRect; | 45 import dwt.internal.cocoa.NSRect; |
46 import dwt.internal.cocoa.NSScrollView; | |
47 import dwt.internal.cocoa.NSSize; | |
32 import dwt.internal.cocoa.NSString; | 48 import dwt.internal.cocoa.NSString; |
33 import dwt.internal.cocoa.NSTableColumn; | 49 import dwt.internal.cocoa.NSTableColumn; |
50 import dwt.internal.cocoa.NSTableHeaderCell; | |
34 import dwt.internal.cocoa.NSTableHeaderView; | 51 import dwt.internal.cocoa.NSTableHeaderView; |
35 import dwt.internal.cocoa.NSTableView; | 52 import dwt.internal.cocoa.NSTableView; |
53 import dwt.internal.cocoa.NSView; | |
36 import dwt.internal.cocoa.OS; | 54 import dwt.internal.cocoa.OS; |
55 import dwt.internal.cocoa.SWTBrowserCell; | |
37 import dwt.internal.cocoa.SWTOutlineView; | 56 import dwt.internal.cocoa.SWTOutlineView; |
38 import dwt.internal.cocoa.SWTScrollView; | 57 import dwt.internal.cocoa.SWTScrollView; |
58 import dwt.internal.cocoa.SWTTableHeaderCell; | |
59 import dwt.internal.cocoa.SWTTableHeaderView; | |
39 import dwt.internal.cocoa.SWTTreeItem; | 60 import dwt.internal.cocoa.SWTTreeItem; |
40 import dwt.internal.cocoa.id; | 61 import dwt.internal.cocoa.id; |
41 | 62 |
42 /** | 63 /** |
43 * Instances of this class provide a selectable user interface object | 64 * Instances of this class provide a selectable user interface object |
73 * } | 94 * } |
74 * }); | 95 * }); |
75 * </pre></code> | 96 * </pre></code> |
76 * </p><p> | 97 * </p><p> |
77 * Note that although this class is a subclass of <code>Composite</code>, | 98 * Note that although this class is a subclass of <code>Composite</code>, |
78 * it does not make sense to add <code>Control</code> children to it, | 99 * it does not normally make sense to add <code>Control</code> children to |
79 * or set a layout on it. | 100 * it, or set a layout on it, unless implementing something like a cell |
101 * editor. | |
80 * </p><p> | 102 * </p><p> |
81 * <dl> | 103 * <dl> |
82 * <dt><b>Styles:</b></dt> | 104 * <dt><b>Styles:</b></dt> |
83 * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL</dd> | 105 * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL</dd> |
84 * <dt><b>Events:</b></dt> | 106 * <dt><b>Events:</b></dt> |
85 * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd> | 107 * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd> |
86 * </dl> | 108 * </dl> |
87 * </p><p> | 109 * </p><p> |
88 * Note: Only one of the styles SINGLE and MULTI may be specified. | 110 * Note: Only one of the styles SINGLE and MULTI may be specified. |
89 * </p><p> | 111 * </p><p> |
90 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | 112 * IMPORTANT: This class is <em>not</em> intended to be subclassed. |
91 * </p> | 113 * </p> |
114 * | |
115 * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a> | |
116 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | |
117 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
92 */ | 118 */ |
93 public class Tree : Composite { | 119 public class Tree : Composite { |
94 NSTableColumn firstColumn, checkColumn; | 120 NSTableColumn firstColumn, checkColumn; |
121 NSBrowserCell dataCell; | |
95 NSTableHeaderView headerView; | 122 NSTableHeaderView headerView; |
96 TreeItem [] items; | 123 TreeItem [] items; |
97 int itemCount; | 124 int itemCount; |
98 TreeColumn [] columns; | 125 TreeColumn [] columns; |
99 TreeColumn sortColumn; | 126 TreeColumn sortColumn; |
100 int columnCount; | 127 int columnCount; |
101 int sortDirection; | 128 int sortDirection; |
129 float /*double*/ levelIndent; | |
102 bool ignoreExpand, ignoreSelect; | 130 bool ignoreExpand, ignoreSelect; |
103 | 131 |
104 /** | 132 /** |
105 * Constructs a new instance of this class given its parent | 133 * Constructs a new instance of this class given its parent |
106 * and a style value describing its behavior and appearance. | 134 * and a style value describing its behavior and appearance. |
126 * </ul> | 154 * </ul> |
127 * | 155 * |
128 * @see DWT#SINGLE | 156 * @see DWT#SINGLE |
129 * @see DWT#MULTI | 157 * @see DWT#MULTI |
130 * @see DWT#CHECK | 158 * @see DWT#CHECK |
159 * @see DWT#FULL_SELECTION | |
160 * @see DWT#VIRTUAL | |
161 * @see DWT#NO_SCROLL | |
131 * @see Widget#checkSubclass | 162 * @see Widget#checkSubclass |
132 * @see Widget#getStyle | 163 * @see Widget#getStyle |
133 */ | 164 */ |
134 public this (Composite parent, int style) { | 165 public this (Composite parent, int style) { |
135 super (parent, checkStyle (style)); | 166 super (parent, checkStyle (style)); |
136 } | 167 } |
137 | 168 |
138 void _addListener (int eventType, Listener listener) { | 169 TreeItem _getItem (TreeItem parentItem, int index, bool create) { |
139 super._addListener (eventType, listener); | |
140 for (int i = 0; i < items.length; i++) { | |
141 if (items [i] !is null) items [i].width = -1; | |
142 } | |
143 } | |
144 | |
145 TreeItem _getItem (TreeItem parentItem, int index) { | |
146 int count; | 170 int count; |
147 TreeItem[] items; | 171 TreeItem[] items; |
148 if (parentItem !is null) { | 172 if (parentItem !is null) { |
149 count = parentItem.itemCount; | 173 count = parentItem.itemCount; |
150 items = parentItem.items; | 174 items = parentItem.items; |
152 count = this.itemCount; | 176 count = this.itemCount; |
153 items = this.items; | 177 items = this.items; |
154 } | 178 } |
155 if (index < 0 || index >= count) return null; | 179 if (index < 0 || index >= count) return null; |
156 TreeItem item = items [index]; | 180 TreeItem item = items [index]; |
157 if (item !is null || (style & DWT.VIRTUAL) is 0) return item; | 181 if (item !is null || (style & DWT.VIRTUAL) is 0 || !create) return item; |
158 item = new TreeItem (this, parentItem, DWT.NONE, index, false); | 182 item = new TreeItem (this, parentItem, DWT.NONE, index, false); |
159 items [index] = item; | 183 items [index] = item; |
160 return item; | 184 return item; |
161 } | 185 } |
186 | |
187 int accessibilityAttributeValue (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { | |
188 | |
189 if (accessible !is null) { | |
190 NSString attribute = new NSString(arg0); | |
191 id returnValue = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF); | |
192 if (returnValue !is null) return returnValue.id; | |
193 } | |
194 | |
195 NSString attributeName = new NSString(arg0); | |
196 | |
197 // Accessibility Verifier queries for a title or description. NSOutlineView doesn't | |
198 // seem to return either, so we return a default description value here. | |
199 if (attributeName.isEqualToString (OS.NSAccessibilityDescriptionAttribute)) { | |
200 return NSString.stringWith("").id; | |
201 } | |
202 | |
203 return super.accessibilityAttributeValue(id, sel, arg0); | |
204 } | |
205 | |
162 | 206 |
163 /** | 207 /** |
164 * Adds the listener to the collection of listeners who will | 208 * Adds the listener to the collection of listeners who will |
165 * be notified when the user changes the receiver's selection, by sending | 209 * be notified when the user changes the receiver's selection, by sending |
166 * it one of the messages defined in the <code>SelectionListener</code> | 210 * it one of the messages defined in the <code>SelectionListener</code> |
261 protected void checkSubclass () { | 305 protected void checkSubclass () { |
262 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); | 306 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); |
263 } | 307 } |
264 | 308 |
265 void clear (TreeItem parentItem, int index, bool all) { | 309 void clear (TreeItem parentItem, int index, bool all) { |
266 // int [] ids = parentItem is null ? childIds : parentItem.childIds; | 310 TreeItem item = _getItem (parentItem, index, false); |
267 // TreeItem item = _getItem (ids [index], false); | 311 if (item !is null) { |
268 // if (item !is null) { | 312 item.clear(); |
269 // item.clear(); | 313 ((NSOutlineView) view).reloadItem (item.handle); |
270 // if (all) { | 314 if (all) { |
271 // clearAll (item, true); | 315 clearAll (item, true); |
272 // } else { | 316 } |
273 // int container = parentItem is null ? OS.kDataBrowserNoItem : parentItem.id; | 317 } |
274 // OS.UpdateDataBrowserItems (handle, container, 1, new int[] {item.id}, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem); | |
275 // } | |
276 // } | |
277 } | 318 } |
278 | 319 |
279 void clearAll (TreeItem parentItem, bool all) { | 320 void clearAll (TreeItem parentItem, bool all) { |
280 // bool update = !inClearAll; | 321 int count = getItemCount (parentItem); |
281 // int count = getItemCount (parentItem); | 322 if (count is 0) return; |
282 // if (count is 0) return; | 323 TreeItem [] children = parentItem is null ? items : parentItem.items; |
283 // inClearAll = true; | 324 for (int i=0; i<count; i++) { |
284 // int [] ids = parentItem is null ? childIds : parentItem.childIds; | 325 TreeItem item = children [i]; |
285 // for (int i=0; i<count; i++) { | 326 if (item !is null) { |
286 // TreeItem item = _getItem (ids [i], false); | 327 item.clear (); |
287 // if (item !is null) { | 328 ((NSOutlineView) view).reloadItem (item.handle); |
288 // item.clear (); | 329 if (all) clearAll (item, true); |
289 // if (all) clearAll (item, true); | 330 } |
290 // } | 331 } |
291 // } | |
292 // if (update) { | |
293 // OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem); | |
294 // inClearAll = false; | |
295 // } | |
296 } | 332 } |
297 | 333 |
298 /** | 334 /** |
299 * Clears the item at the given zero-relative index in the receiver. | 335 * Clears the item at the given zero-relative index in the receiver. |
300 * The text, icon and other attributes of the item are set to the default | 336 * The text, icon and other attributes of the item are set to the default |
345 * @since 3.2 | 381 * @since 3.2 |
346 */ | 382 */ |
347 public void clearAll (bool all) { | 383 public void clearAll (bool all) { |
348 checkWidget (); | 384 checkWidget (); |
349 clearAll (null, all); | 385 clearAll (null, all); |
386 } | |
387 | |
388 void clearCustomWidths (TreeItem item) { | |
389 item.customWidth = -1; | |
390 for (int i = 0; i < item.itemCount; i++) { | |
391 clearCustomWidths (items[i]); | |
392 } | |
350 } | 393 } |
351 | 394 |
352 public Point computeSize (int wHint, int hHint, bool changed) { | 395 public Point computeSize (int wHint, int hHint, bool changed) { |
353 checkWidget (); | 396 checkWidget (); |
354 int width = 0, height = 0; | 397 int width = 0, height = 0; |
372 if ((style & DWT.CHECK) !is 0) width += getCheckColumnWidth (); | 415 if ((style & DWT.CHECK) !is 0) width += getCheckColumnWidth (); |
373 } else { | 416 } else { |
374 width = wHint; | 417 width = wHint; |
375 } | 418 } |
376 if (hHint is DWT.DEFAULT) { | 419 if (hHint is DWT.DEFAULT) { |
377 height = (cast(NSTableView)view).numberOfRows() * getItemHeight () + getHeaderHeight(); | 420 height = (int)/*64*/(cast(NSOutlineView) view).numberOfRows () * getItemHeight () + getHeaderHeight (); |
378 } else { | 421 } else { |
379 height = hHint; | 422 height = hHint; |
380 } | 423 } |
381 if (width <= 0) width = DEFAULT_WIDTH; | 424 if (width <= 0) width = DEFAULT_WIDTH; |
382 if (height <= 0) height = DEFAULT_HEIGHT; | 425 if (height <= 0) height = DEFAULT_HEIGHT; |
383 Rectangle rect = computeTrim (0, 0, width, height); | 426 Rectangle rect = computeTrim (0, 0, width, height); |
384 return new Point (rect.width, rect.height); | 427 return new Point (rect.width, rect.height); |
385 } | 428 } |
386 | 429 |
430 void createColumn (TreeItem item, int index) { | |
431 if (item.items !is null) { | |
432 for (int i = 0; i < item.items.length; i++) { | |
433 if (item.items[i] !is null) createColumn (item.items[i], index); | |
434 } | |
435 } | |
436 String [] strings = item.strings; | |
437 if (strings !is null) { | |
438 String [] temp = new String [columnCount]; | |
439 System.arraycopy (strings, 0, temp, 0, index); | |
440 System.arraycopy (strings, index, temp, index+1, columnCount-index-1); | |
441 temp [index] = ""; | |
442 item.strings = temp; | |
443 } | |
444 if (index is 0) item.text = ""; | |
445 Image [] images = item.images; | |
446 if (images !is null) { | |
447 Image [] temp = new Image [columnCount]; | |
448 System.arraycopy (images, 0, temp, 0, index); | |
449 System.arraycopy (images, index, temp, index+1, columnCount-index-1); | |
450 item.images = temp; | |
451 } | |
452 if (index is 0) item.image = null; | |
453 Color [] cellBackground = item.cellBackground; | |
454 if (cellBackground !is null) { | |
455 Color [] temp = new Color [columnCount]; | |
456 System.arraycopy (cellBackground, 0, temp, 0, index); | |
457 System.arraycopy (cellBackground, index, temp, index+1, columnCount-index-1); | |
458 item.cellBackground = temp; | |
459 } | |
460 Color [] cellForeground = item.cellForeground; | |
461 if (cellForeground !is null) { | |
462 Color [] temp = new Color [columnCount]; | |
463 System.arraycopy (cellForeground, 0, temp, 0, index); | |
464 System.arraycopy (cellForeground, index, temp, index+1, columnCount-index-1); | |
465 item.cellForeground = temp; | |
466 } | |
467 Font [] cellFont = item.cellFont; | |
468 if (cellFont !is null) { | |
469 Font [] temp = new Font [columnCount]; | |
470 System.arraycopy (cellFont, 0, temp, 0, index); | |
471 System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1); | |
472 item.cellFont = temp; | |
473 } | |
474 } | |
475 | |
387 void createHandle () { | 476 void createHandle () { |
388 SWTScrollView scrollWidget = cast(SWTScrollView)new SWTScrollView().alloc(); | 477 NSScrollView scrollWidget = cast(NSScrollView) new SWTScrollView ().alloc (); |
389 scrollWidget.initWithFrame(new NSRect ()); | 478 scrollWidget.initWithFrame (new NSRect ()); |
390 scrollWidget.setHasHorizontalScroller(true); | 479 scrollWidget.setHasHorizontalScroller (true); |
391 scrollWidget.setHasVerticalScroller(true); | 480 scrollWidget.setHasVerticalScroller (true); |
392 scrollWidget.setAutohidesScrollers(true); | 481 scrollWidget.setAutohidesScrollers (true); |
393 scrollWidget.setBorderType(hasBorder() ? OS.NSBezelBorder : OS.NSNoBorder); | 482 scrollWidget.setBorderType(hasBorder () ? OS.NSBezelBorder : OS.NSNoBorder); |
394 scrollWidget.setTag(jniRef); | |
395 | 483 |
396 NSOutlineView widget = cast(NSOutlineView)new SWTOutlineView().alloc(); | 484 NSOutlineView widget = cast(NSOutlineView) new SWTOutlineView ().alloc (); |
397 widget.initWithFrame(new NSRect()); | 485 widget.initWithFrame (new NSRect ()); |
398 widget.setAllowsMultipleSelection((style & DWT.MULTI) !is 0); | 486 widget.setAllowsMultipleSelection ((style & DWT.MULTI) !is 0); |
399 widget.setAutoresizesOutlineColumn(false); | 487 widget.setAllowsColumnReordering (false); |
400 widget.setAutosaveExpandedItems(true); | 488 widget.setAutoresizesOutlineColumn (false); |
401 widget.setDataSource(widget); | 489 widget.setAutosaveExpandedItems (true); |
402 widget.setDelegate(widget); | 490 widget.setDataSource (widget); |
403 widget.setDoubleAction(OS.sel_sendDoubleSelection); | 491 widget.setDelegate (widget); |
404 if (!hasBorder()) widget.setFocusRingType(OS.NSFocusRingTypeNone); | 492 widget.setDoubleAction (OS.sel_sendDoubleSelection); |
405 widget.setTag(jniRef); | 493 if (!hasBorder ()) widget.setFocusRingType (OS.NSFocusRingTypeNone); |
406 | 494 |
407 headerView = widget.headerView(); | 495 headerView = (NSTableHeaderView)new SWTTableHeaderView ().alloc ().init (); |
408 headerView.retain(); | 496 widget.setHeaderView (null); |
409 widget.setHeaderView(null); | |
410 | 497 |
411 NSString str = NSString.stringWith(""); | 498 NSString str = NSString.stringWith (""); |
412 if ((style & DWT.CHECK) !is 0) { | 499 if ((style & DWT.CHECK) !is 0) { |
413 checkColumn = cast(NSTableColumn)new NSTableColumn().alloc(); | 500 checkColumn = cast(NSTableColumn) new NSTableColumn ().alloc (); |
414 checkColumn.initWithIdentifier(str); | 501 checkColumn.initWithIdentifier (checkColumn); |
415 checkColumn.headerCell().setTitle(str); | 502 checkColumn.headerCell ().setTitle (str); |
416 widget.addTableColumn (checkColumn); | 503 widget.addTableColumn (checkColumn); |
417 widget.setOutlineTableColumn(checkColumn); | 504 widget.setOutlineTableColumn (checkColumn); |
418 NSButtonCell cell = cast(NSButtonCell)new NSButtonCell().alloc().init(); | 505 NSButtonCell cell = cast(NSButtonCell) new NSButtonCell ().alloc ().init (); |
419 checkColumn.setDataCell(cell); | 506 checkColumn.setDataCell (cell); |
420 cell.setButtonType(OS.NSSwitchButton); | 507 cell.setButtonType (OS.NSSwitchButton); |
421 cell.setImagePosition(OS.NSImageOnly); | 508 cell.setImagePosition (OS.NSImageOnly); |
422 cell.setAllowsMixedState(true); | 509 cell.setAllowsMixedState (true); |
423 checkColumn.setWidth(getCheckColumnWidth()); | 510 checkColumn.setWidth (getCheckColumnWidth ()); |
424 checkColumn.setResizingMask(OS.NSTableColumnNoResizing); | 511 checkColumn.setResizingMask (OS.NSTableColumnNoResizing); |
425 checkColumn.setEditable(false); | 512 checkColumn.setEditable (false); |
426 cell.release(); | 513 cell.release (); |
427 } | 514 } |
428 | 515 |
429 firstColumn = cast(NSTableColumn)new NSTableColumn().alloc(); | 516 firstColumn = cast(NSTableColumn) new NSTableColumn ().alloc (); |
430 firstColumn.initWithIdentifier(str); | 517 firstColumn.initWithIdentifier (firstColumn); |
431 firstColumn.headerCell().setTitle(str); | 518 firstColumn.setMinWidth(0); |
519 firstColumn.headerCell ().setTitle (str); | |
432 widget.addTableColumn (firstColumn); | 520 widget.addTableColumn (firstColumn); |
433 widget.setOutlineTableColumn(firstColumn); | 521 widget.setOutlineTableColumn (firstColumn); |
434 NSBrowserCell cell = cast(NSBrowserCell)new NSBrowserCell().alloc().init(); | 522 dataCell = cast(NSBrowserCell)new SWTBrowserCell ().alloc ().init (); |
435 cell.setLeaf(true); | 523 dataCell.setLeaf (true); |
436 firstColumn.setDataCell(cell); | 524 firstColumn.setDataCell (dataCell); |
437 cell.release(); | 525 levelIndent = widget.indentationPerLevel (); |
438 | 526 |
439 scrollView = scrollWidget; | 527 scrollView = scrollWidget; |
440 view = widget; | 528 view = widget; |
441 scrollView.setDocumentView(widget); | |
442 parent.contentView().addSubview_(scrollView); | |
443 } | 529 } |
444 | 530 |
445 void createItem (TreeColumn column, int index) { | 531 void createItem (TreeColumn column, int index) { |
446 if (!(0 <= index && index <= columnCount)) error (DWT.ERROR_INVALID_RANGE); | 532 if (!(0 <= index && index <= columnCount)) error (DWT.ERROR_INVALID_RANGE); |
447 if (index is 0) { | 533 if (index is 0) { |
456 } | 542 } |
457 NSTableColumn nsColumn; | 543 NSTableColumn nsColumn; |
458 if (columnCount is 0) { | 544 if (columnCount is 0) { |
459 //TODO - clear attributes, alignment etc. | 545 //TODO - clear attributes, alignment etc. |
460 nsColumn = firstColumn; | 546 nsColumn = firstColumn; |
547 nsColumn.retain(); | |
461 firstColumn = null; | 548 firstColumn = null; |
462 } else { | 549 } else { |
463 //TODO - set attributes, alignment etc. | 550 //TODO - set attributes, alignment etc. |
464 NSString str = NSString.stringWith(""); | 551 NSOutlineView outlineView = (NSOutlineView)view; |
465 nsColumn = cast(NSTableColumn)new NSTableColumn().alloc(); | 552 NSString str = NSString.stringWith (""); |
466 nsColumn.initWithIdentifier(str); | 553 nsColumn = cast(NSTableColumn) new NSTableColumn ().alloc (); |
467 nsColumn.headerCell().setTitle(str); | 554 nsColumn.initWithIdentifier (nsColumn); |
468 (cast(NSTableView)view).addTableColumn (nsColumn); | 555 nsColumn.setMinWidth(0); |
556 nsColumn.headerCell ().setTitle (str); | |
557 outlineView.addTableColumn (nsColumn); | |
469 int checkColumn = (style & DWT.CHECK) !is 0 ? 1 : 0; | 558 int checkColumn = (style & DWT.CHECK) !is 0 ? 1 : 0; |
470 (cast(NSTableView)view).moveColumn (columnCount + checkColumn, index + checkColumn); | 559 outlineView.moveColumn (columnCount + checkColumn, index + checkColumn); |
471 NSBrowserCell cell = cast(NSBrowserCell)new NSBrowserCell().alloc().init(); | 560 nsColumn.setDataCell (dataCell); |
472 cell.setLeaf(true); | 561 if (index is 0) { |
473 nsColumn.setDataCell(cell); | 562 outlineView.setOutlineTableColumn (nsColumn); |
474 cell.release(); | 563 } |
475 } | 564 } |
565 column.createJNIRef (); | |
566 NSTableHeaderCell headerCell = (NSTableHeaderCell)new SWTTableHeaderCell ().alloc ().init (); | |
567 nsColumn.setHeaderCell (headerCell); | |
568 display.addWidget (headerCell, column); | |
476 column.nsColumn = nsColumn; | 569 column.nsColumn = nsColumn; |
477 nsColumn.headerCell().setTitle(NSString.stringWith("")); | 570 nsColumn.setWidth (0); |
478 nsColumn.setWidth(0); | |
479 System.arraycopy (columns, index, columns, index + 1, columnCount++ - index); | 571 System.arraycopy (columns, index, columns, index + 1, columnCount++ - index); |
480 columns [index] = column; | 572 columns [index] = column; |
481 if (columnCount > 1) { | 573 if (columnCount > 1) { |
482 for (int i=0; i<items.length; i++) { | 574 for (int i=0; i<items.length; i++) { |
483 TreeItem item = items [i]; | 575 TreeItem item = items [i]; |
484 if (item !is null) { | 576 if (item !is null) createColumn (item, index); |
485 String [] strings = item.strings; | 577 } |
486 if (strings !is null) { | 578 } else { |
487 String [] temp = new String [columnCount]; | 579 for (int i = 0; i < itemCount; i++) { |
488 System.arraycopy (strings, 0, temp, 0, index); | 580 clearCustomWidths (items[i]); |
489 System.arraycopy (strings, index, temp, index+1, columnCount-index-1); | |
490 temp [index] = ""; | |
491 item.strings = temp; | |
492 } | |
493 if (index is 0) item.text = ""; | |
494 Image [] images = item.images; | |
495 if (images !is null) { | |
496 Image [] temp = new Image [columnCount]; | |
497 System.arraycopy (images, 0, temp, 0, index); | |
498 System.arraycopy (images, index, temp, index+1, columnCount-index-1); | |
499 item.images = temp; | |
500 } | |
501 if (index is 0) item.image = null; | |
502 Color [] cellBackground = item.cellBackground; | |
503 if (cellBackground !is null) { | |
504 Color [] temp = new Color [columnCount]; | |
505 System.arraycopy (cellBackground, 0, temp, 0, index); | |
506 System.arraycopy (cellBackground, index, temp, index+1, columnCount-index-1); | |
507 item.cellBackground = temp; | |
508 } | |
509 Color [] cellForeground = item.cellForeground; | |
510 if (cellForeground !is null) { | |
511 Color [] temp = new Color [columnCount]; | |
512 System.arraycopy (cellForeground, 0, temp, 0, index); | |
513 System.arraycopy (cellForeground, index, temp, index+1, columnCount-index-1); | |
514 item.cellForeground = temp; | |
515 } | |
516 Font [] cellFont = item.cellFont; | |
517 if (cellFont !is null) { | |
518 Font [] temp = new Font [columnCount]; | |
519 System.arraycopy (cellFont, 0, temp, 0, index); | |
520 System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1); | |
521 item.cellFont = temp; | |
522 } | |
523 } | |
524 } | 581 } |
525 } | 582 } |
526 } | 583 } |
527 | 584 |
528 void createItem (TreeItem item, TreeItem parentItem, int index) { | 585 void createItem (TreeItem item, TreeItem parentItem, int index) { |
529 int count; | 586 int count; |
530 TreeItem[] items; | 587 TreeItem [] items; |
531 if (parentItem !is null) { | 588 if (parentItem !is null) { |
532 count = parentItem.itemCount; | 589 count = parentItem.itemCount; |
533 items = parentItem.items; | 590 items = parentItem.items; |
534 } else { | 591 } else { |
535 count = this.itemCount; | 592 count = this.itemCount; |
547 this.items = items; | 604 this.items = items; |
548 } | 605 } |
549 } | 606 } |
550 System.arraycopy (items, index, items, index + 1, count++ - index); | 607 System.arraycopy (items, index, items, index + 1, count++ - index); |
551 items [index] = item; | 608 items [index] = item; |
552 item.items = new TreeItem[4]; | 609 item.items = new TreeItem [4]; |
553 item.createJNIRef(); | 610 SWTTreeItem handle = (SWTTreeItem) new SWTTreeItem ().alloc ().init (); |
554 SWTTreeItem handle = cast(SWTTreeItem)new SWTTreeItem().alloc().init(); | |
555 handle.setTag(item.jniRef); | |
556 item.handle = handle; | 611 item.handle = handle; |
612 item.createJNIRef (); | |
613 item.register (); | |
557 if (parentItem !is null) { | 614 if (parentItem !is null) { |
558 parentItem.itemCount = count; | 615 parentItem.itemCount = count; |
559 } else { | 616 } else { |
560 this.itemCount = count; | 617 this.itemCount = count; |
561 } | 618 } |
562 //TODO ? | 619 ignoreExpand = true; |
563 (cast(NSTableView)view).reloadData(); | 620 NSOutlineView widget = cast(NSOutlineView)view; |
621 widget.reloadItem(parentItem !is null ? parentItem.handle : null, true); | |
622 ignoreExpand = false; | |
564 } | 623 } |
565 | 624 |
566 void createWidget () { | 625 void createWidget () { |
567 super.createWidget (); | 626 super.createWidget (); |
568 items = new TreeItem [4]; | 627 items = new TreeItem [4]; |
585 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 644 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
586 * </ul> | 645 * </ul> |
587 */ | 646 */ |
588 public void deselectAll () { | 647 public void deselectAll () { |
589 checkWidget (); | 648 checkWidget (); |
590 NSTableView widget = cast(NSTableView)view; | 649 NSTableView widget = cast(NSOutlineView) view; |
591 ignoreSelect = true; | 650 ignoreSelect = true; |
592 widget.deselectAll(null); | 651 widget.deselectAll (null); |
593 ignoreSelect = false; | 652 ignoreSelect = false; |
594 } | 653 } |
595 | 654 |
655 void deregister () { | |
656 super.deregister (); | |
657 display.removeWidget (headerView); | |
658 display.removeWidget (dataCell); | |
659 } | |
660 | |
661 /** | |
662 * Deselects an item in the receiver. If the item was already | |
663 * deselected, it remains deselected. | |
664 * | |
665 * @param item the item to be deselected | |
666 * | |
667 * @exception IllegalArgumentException <ul> | |
668 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
669 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
670 * </ul> | |
671 * @exception DWTException <ul> | |
672 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
673 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
674 * </ul> | |
675 * | |
676 * @since 3.4 | |
677 */ | |
596 public void deselect (TreeItem item) { | 678 public void deselect (TreeItem item) { |
597 checkWidget (); | 679 checkWidget (); |
598 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | 680 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); |
599 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | 681 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); |
600 // ignoreSelect = true; | 682 // ignoreSelect = true; |
681 item.cellFont = temp; | 763 item.cellFont = temp; |
682 } | 764 } |
683 } | 765 } |
684 } | 766 } |
685 } | 767 } |
686 // if (columnCount is 1) { | 768 |
687 // column_id = column.id; idCount = 0; | 769 int oldIndex = (int)/*64*/((NSOutlineView)view).columnWithIdentifier (column.nsColumn); |
688 // DataBrowserListViewHeaderDesc desc = new DataBrowserListViewHeaderDesc (); | 770 |
689 // desc.version = OS.kDataBrowserListViewLatestHeaderDesc; | 771 if (columnCount is 1) { |
690 // short [] width = new short [1]; | 772 //TODO - reset attributes |
691 // OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width); | 773 firstColumn = column.nsColumn; |
692 // desc.minimumWidth = desc.maximumWidth = width [0]; | 774 firstColumn.setWidth (0); |
693 // int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, null, 0); | 775 } else { |
694 // desc.titleString = str; | 776 if (index is 0) { |
695 // OS.SetDataBrowserListViewHeaderDesc (handle, column_id, desc); | 777 ((NSOutlineView)view).setOutlineTableColumn(columns[1].nsColumn); |
696 // OS.CFRelease (str); | 778 } |
697 // } else { | 779 ((NSOutlineView)view).removeTableColumn(column.nsColumn); |
698 // int [] disclosure = new int [1]; | 780 } |
699 // bool [] expandableRows = new bool [1]; | |
700 // OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, expandableRows); | |
701 // if (disclosure [0] is column.id) { | |
702 // TreeColumn firstColumn = columns [1]; | |
703 // firstColumn.style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); | |
704 // firstColumn.style |= DWT.LEFT; | |
705 // firstColumn.updateHeader(); | |
706 // OS.SetDataBrowserListViewDisclosureColumn (handle, firstColumn.id, expandableRows [0]); | |
707 // } | |
708 // if (OS.RemoveDataBrowserTableViewColumn (handle, column.id) !is OS.noErr) { | |
709 // error (DWT.ERROR_ITEM_NOT_REMOVED); | |
710 // } | |
711 // } | |
712 System.arraycopy (columns, index + 1, columns, index, --columnCount - index); | 781 System.arraycopy (columns, index + 1, columns, index, --columnCount - index); |
713 columns [columnCount] = null; | 782 columns [columnCount] = null; |
714 for (int i=index; i<columnCount; i++) { | 783 |
715 columns [i].sendEvent (DWT.Move); | 784 NSArray array = ((NSOutlineView)view).tableColumns (); |
785 int arraySize = (int)/*64*/array.count (); | |
786 for (int i = oldIndex; i < arraySize; i++) { | |
787 int /*long*/ columnId = array.objectAtIndex (i).id; | |
788 for (int j = 0; j < columnCount; j++) { | |
789 if (columns[j].nsColumn.id is columnId) { | |
790 columns [j].sendEvent (DWT.Move); | |
791 break; | |
792 } | |
793 } | |
716 } | 794 } |
717 } | 795 } |
718 | 796 |
719 void destroyItem (TreeItem item) { | 797 void destroyItem (TreeItem item) { |
720 int count; | 798 int count; |
735 // if (index !is itemCount - 1) fixSelection (index, false); | 813 // if (index !is itemCount - 1) fixSelection (index, false); |
736 System.arraycopy (items, index + 1, items, index, --count - index); | 814 System.arraycopy (items, index + 1, items, index, --count - index); |
737 items [count] = null; | 815 items [count] = null; |
738 if (parentItem !is null) { | 816 if (parentItem !is null) { |
739 parentItem.itemCount = count; | 817 parentItem.itemCount = count; |
740 (cast(NSOutlineView)view).reloadItem_reloadChildren_(parentItem.handle, true); | 818 (cast(NSOutlineView) view).reloadItem (parentItem.handle, true); |
741 } else { | 819 } else { |
742 this.itemCount = count; | 820 this.itemCount = count; |
743 (cast(NSOutlineView)view).reloadItem_(null); | 821 (cast(NSOutlineView) view).reloadItem (null); |
744 } | 822 } |
745 | 823 |
746 //noteNumberOfRowsChanged was causing crashes whenever | 824 //noteNumberOfRowsChanged was causing crashes whenever |
747 //a TreeItem was disposed. | 825 //a TreeItem was disposed. |
748 //Using reloadItem avoids the crashes. | 826 //Using reloadItem avoids the crashes. |
753 | 831 |
754 // setScrollWidth (true); | 832 // setScrollWidth (true); |
755 // fixScrollBar (); | 833 // fixScrollBar (); |
756 } | 834 } |
757 | 835 |
836 void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, int /*long*/ cellFrame, int /*long*/ view) { | |
837 NSRect rect = new NSRect (); | |
838 OS.memmove (rect, cellFrame, NSRect.sizeof); | |
839 | |
840 NSOutlineView outlineView = (NSOutlineView)this.view; | |
841 NSBrowserCell cell = new NSBrowserCell (id); | |
842 NSRange rowsRange = outlineView.rowsInRect (rect); | |
843 int rowIndex = (int)/*64*/rowsRange.location; | |
844 TreeItem item = (TreeItem) display.getWidget (outlineView.itemAtRow (rowIndex).id); | |
845 int columnIndex = 0; | |
846 id nsColumn = null; | |
847 int nsColumnIndex = 0; | |
848 if (columnCount !is 0) { | |
849 NSIndexSet columnsSet = outlineView.columnIndexesInRect (rect); | |
850 nsColumnIndex = (int)/*64*/columnsSet.firstIndex (); | |
851 NSArray nsColumns = outlineView.tableColumns (); | |
852 nsColumn = nsColumns.objectAtIndex (nsColumnIndex); | |
853 for (int i = 0; i < columnCount; i++) { | |
854 if (columns[i].nsColumn.id is nsColumn.id) { | |
855 columnIndex = indexOf (columns[i]); | |
856 break; | |
857 } | |
858 } | |
859 } | |
860 | |
861 Color background = item.cellBackground !is null ? item.cellBackground [columnIndex] : null; | |
862 if (background is null) background = item.background; | |
863 bool drawBackground = background !is null; | |
864 bool drawForeground = true; | |
865 bool isSelected = outlineView.isRowSelected (rowIndex); | |
866 bool drawSelection = isSelected; | |
867 | |
868 NSColor nsSelectionBackground = null; | |
869 NSColor nsSelectionForeground = null; | |
870 if (isSelected) { | |
871 if (isFocusControl ()) { | |
872 nsSelectionForeground = NSColor.alternateSelectedControlTextColor (); | |
873 } else { | |
874 nsSelectionForeground = NSColor.selectedControlTextColor (); | |
875 } | |
876 nsSelectionForeground = nsSelectionForeground.colorUsingColorSpace (NSColorSpace.deviceRGBColorSpace ()); | |
877 nsSelectionBackground = cell.highlightColorInView (outlineView); | |
878 nsSelectionBackground = nsSelectionBackground.colorUsingColorSpace (NSColorSpace.deviceRGBColorSpace ()); | |
879 } | |
880 | |
881 NSRect fullRect = new NSRect (); | |
882 fullRect.y = rect.y; fullRect.height = rect.height; | |
883 if (columnCount is 0) { | |
884 fullRect.x = rect.x; | |
885 if (item.customWidth !is -1) { | |
886 fullRect.width = item.customWidth; | |
887 } else { | |
888 NSSize contentSize = cell.cellSizeForBounds (rect); | |
889 fullRect.width = contentSize.width; | |
890 } | |
891 } else { | |
892 NSSize spacing = outlineView.intercellSpacing (); | |
893 if (nsColumn.id is outlineView.outlineTableColumn ().id) { | |
894 NSRect columnRect = outlineView.rectOfColumn (nsColumnIndex); | |
895 fullRect.x = columnRect.x; fullRect.width = columnRect.width + spacing.width; | |
896 } else { | |
897 fullRect.x = rect.x; | |
898 fullRect.width = rect.width + spacing.width; | |
899 } | |
900 } | |
901 | |
902 if (hooks (DWT.EraseItem)) { | |
903 NSRect eraseItemRect = null; | |
904 // TODO how to handle rearranged columns? The third clause below ensures that | |
905 // there are either 0 columns or that column 0 is still the first physical column. | |
906 if (columnIndex is 0 && (style & DWT.CHECK) !is 0 && (columnCount is 0 || outlineView.columnWithIdentifier (columns[0].nsColumn) is 1)) { | |
907 eraseItemRect = new NSRect (); | |
908 eraseItemRect.y = fullRect.y; | |
909 eraseItemRect.width = fullRect.x + fullRect.width; | |
910 eraseItemRect.height = fullRect.height; | |
911 } else { | |
912 eraseItemRect = fullRect; | |
913 } | |
914 GCData data = new GCData (); | |
915 data.paintRect = eraseItemRect; | |
916 GC gc = GC.cocoa_new (this, data); | |
917 gc.setFont (item.getFont (columnIndex)); | |
918 if (isSelected) { | |
919 float /*double*/[] components = new float /*double*/[(int)/*64*/nsSelectionForeground.numberOfComponents ()]; | |
920 nsSelectionForeground.getComponents (components); | |
921 Color selectionForeground = Color.cocoa_new (display, components); | |
922 gc.setForeground (selectionForeground); | |
923 components = new float /*double*/[(int)/*64*/nsSelectionBackground.numberOfComponents ()]; | |
924 nsSelectionBackground.getComponents (components); | |
925 Color selectionBackground = Color.cocoa_new (display, components); | |
926 gc.setBackground (selectionBackground); | |
927 } else { | |
928 gc.setForeground (item.getForeground (columnIndex)); | |
929 gc.setBackground (item.getBackground (columnIndex)); | |
930 } | |
931 | |
932 Event event = new Event (); | |
933 event.item = item; | |
934 event.gc = gc; | |
935 event.index = columnIndex; | |
936 event.detail = DWT.FOREGROUND; | |
937 if (drawBackground) event.detail |= DWT.BACKGROUND; | |
938 if (isSelected) event.detail |= DWT.SELECTED; | |
939 event.x = (int)eraseItemRect.x; | |
940 event.y = (int)eraseItemRect.y; | |
941 event.width = (int)eraseItemRect.width; | |
942 event.height = (int)eraseItemRect.height; | |
943 sendEvent (DWT.EraseItem, event); | |
944 gc.dispose (); | |
945 if (item.isDisposed ()) return; | |
946 if (!event.doit) { | |
947 drawForeground = drawBackground = drawSelection = false; | |
948 } else { | |
949 drawBackground = drawBackground && (event.detail & DWT.BACKGROUND) !is 0; | |
950 drawForeground = (event.detail & DWT.FOREGROUND) !is 0; | |
951 drawSelection = drawSelection && (event.detail & DWT.SELECTED) !is 0; | |
952 } | |
953 if (drawSelection) { | |
954 NSRect selectionRect = new NSRect (); | |
955 selectionRect.y = rect.y; selectionRect.height = rect.height; | |
956 if (columnCount > 0) { | |
957 NSRect columnRect = outlineView.rectOfColumn (nsColumnIndex); | |
958 selectionRect.x = columnRect.x; selectionRect.width = columnRect.width; | |
959 } else { | |
960 NSRect rowRect = outlineView.rectOfRow (rowIndex); | |
961 if ((style & DWT.CHECK) !is 0) { | |
962 /* highlighting at this stage draws over the checkbox, so don't include its column */ | |
963 int checkWidth = (int)/*64*/checkColumn.width (); | |
964 selectionRect.x = checkWidth; | |
965 selectionRect.width = rowRect.width - checkWidth; | |
966 } else { | |
967 selectionRect.width = rowRect.width; | |
968 } | |
969 } | |
970 callSuper (outlineView.id, OS.sel_highlightSelectionInClipRect_, selectionRect); | |
971 } | |
972 } | |
973 | |
974 if (drawBackground && !drawSelection) { | |
975 NSGraphicsContext context = NSGraphicsContext.currentContext (); | |
976 context.saveGraphicsState (); | |
977 float[] colorRGB = background.handle; | |
978 NSColor color = NSColor.colorWithDeviceRed (colorRGB[0], colorRGB[1], colorRGB[2], 1f); | |
979 color.setFill (); | |
980 NSBezierPath.fillRect (fullRect); | |
981 context.restoreGraphicsState (); | |
982 } | |
983 | |
984 if (drawForeground) { | |
985 cell.setHighlighted (false); | |
986 callSuper (id, sel, rect, view); | |
987 } | |
988 | |
989 if (hooks (DWT.PaintItem)) { | |
990 NSRect contentRect = cell.titleRectForBounds (rect); | |
991 NSSize contentSize = cell.cellSizeForBounds (rect); | |
992 | |
993 GCData data = new GCData (); | |
994 // TODO how to handle rearranged columns? The third clause below ensures that | |
995 // there are either 0 columns or that column 0 is still the first physical column. | |
996 if (columnIndex is 0 && (style & DWT.CHECK) !is 0 && (columnCount is 0 || outlineView.columnWithIdentifier (columns[0].nsColumn) is 1)) { | |
997 NSRect gcRect = new NSRect (); | |
998 gcRect.y = fullRect.y; | |
999 gcRect.width = fullRect.x + fullRect.width; | |
1000 gcRect.height = fullRect.height; | |
1001 data.paintRect = gcRect; | |
1002 } else { | |
1003 data.paintRect = fullRect; | |
1004 } | |
1005 GC gc = GC.cocoa_new (this, data); | |
1006 gc.setFont (item.getFont (columnIndex)); | |
1007 if (isSelected) { | |
1008 float /*double*/[] components = new float /*double*/[(int)/*64*/nsSelectionForeground.numberOfComponents ()]; | |
1009 nsSelectionForeground.getComponents (components); | |
1010 Color selectionForeground = Color.cocoa_new (display, components); | |
1011 gc.setForeground (selectionForeground); | |
1012 components = new float /*double*/[(int)/*64*/nsSelectionBackground.numberOfComponents ()]; | |
1013 nsSelectionBackground.getComponents (components); | |
1014 Color selectionBackground = Color.cocoa_new (display, components); | |
1015 gc.setBackground (selectionBackground); | |
1016 gc.setBackground (display.getSystemColor (DWT.COLOR_GREEN)); | |
1017 } else { | |
1018 gc.setForeground (item.getForeground (columnIndex)); | |
1019 gc.setBackground (item.getBackground (columnIndex)); | |
1020 } | |
1021 | |
1022 Event event = new Event (); | |
1023 event.item = item; | |
1024 event.gc = gc; | |
1025 event.index = columnIndex; | |
1026 if (isSelected) event.detail |= DWT.SELECTED; | |
1027 event.x = (int)contentRect.x; | |
1028 event.y = (int)contentRect.y; | |
1029 event.width = (int)Math.ceil (contentSize.width); | |
1030 event.height = (int)Math.ceil (fullRect.height); | |
1031 sendEvent (DWT.PaintItem, event); | |
1032 gc.dispose (); | |
1033 } | |
1034 } | |
758 | 1035 |
759 void fixScrollBar () { | 1036 void fixScrollBar () { |
760 /* | 1037 /* |
761 * Bug in the Macintosh. For some reason, the data browser does not update | 1038 * Bug in the Macintosh. For some reason, the data browser does not update |
762 * the vertical scrollbar when it is scrolled to the bottom and items are | 1039 * the vertical scrollbar when it is scrolled to the bottom and items are |
773 | 1050 |
774 int getCheckColumnWidth () { | 1051 int getCheckColumnWidth () { |
775 return 20; //TODO - compute width | 1052 return 20; //TODO - compute width |
776 } | 1053 } |
777 | 1054 |
1055 TreeColumn getColumn (id id) { | |
1056 for (int i = 0; i < columnCount; i++) { | |
1057 if (columns[i].nsColumn.id is id.id) { | |
1058 return columns[i]; | |
1059 } | |
1060 } | |
1061 return null; | |
1062 } | |
1063 | |
778 /** | 1064 /** |
779 * Returns the column at the given, zero-relative index in the | 1065 * Returns the column at the given, zero-relative index in the |
780 * receiver. Throws an exception if the index is out of range. | 1066 * receiver. Throws an exception if the index is out of range. |
781 * Columns are returned in the order that they were created. | 1067 * Columns are returned in the order that they were created. |
782 * If no <code>TreeColumn</code>s were created by the programmer, | 1068 * If no <code>TreeColumn</code>s were created by the programmer, |
860 * @since 3.2 | 1146 * @since 3.2 |
861 */ | 1147 */ |
862 public int [] getColumnOrder () { | 1148 public int [] getColumnOrder () { |
863 checkWidget (); | 1149 checkWidget (); |
864 int [] order = new int [columnCount]; | 1150 int [] order = new int [columnCount]; |
865 int [] position = new int [1]; | 1151 for (int i = 0; i < columnCount; i++) { |
866 for (int i=0; i<columnCount; i++) { | |
867 TreeColumn column = columns [i]; | 1152 TreeColumn column = columns [i]; |
868 // OS.GetDataBrowserTableViewColumnPosition (handle, column.id, position); | 1153 int index = ((NSOutlineView)view).columnWithIdentifier (column.nsColumn); |
869 // if ((style & DWT.CHECK) !is 0) position [0] -= 1; | 1154 if ((style & DWT.CHECK) !is 0) index -= 1; |
870 order [position [0]] = i; | 1155 order [index] = i; |
871 } | 1156 } |
872 return order; | 1157 return order; |
873 } | 1158 } |
874 | 1159 |
875 /** | 1160 /** |
937 * | 1222 * |
938 * @since 3.1 | 1223 * @since 3.1 |
939 */ | 1224 */ |
940 public int getHeaderHeight () { | 1225 public int getHeaderHeight () { |
941 checkWidget (); | 1226 checkWidget (); |
942 NSTableHeaderView headerView = (cast(NSTableView)view).headerView(); | 1227 NSTableHeaderView headerView = (cast(NSOutlineView) view).headerView (); |
943 if (headerView is null) return 0; | 1228 if (headerView is null) return 0; |
944 return cast(int)headerView.bounds().height; | 1229 return cast(int) headerView.bounds ().height; |
945 } | 1230 } |
946 | 1231 |
947 /** | 1232 /** |
948 * Returns <code>true</code> if the receiver's header is visible, | 1233 * Returns <code>true</code> if the receiver's header is visible, |
949 * and <code>false</code> otherwise. | 1234 * and <code>false</code> otherwise. |
963 * | 1248 * |
964 * @since 3.1 | 1249 * @since 3.1 |
965 */ | 1250 */ |
966 public bool getHeaderVisible () { | 1251 public bool getHeaderVisible () { |
967 checkWidget (); | 1252 checkWidget (); |
968 return (cast(NSTableView)view).headerView() !is null; | 1253 return (cast(NSOutlineView) view).headerView () !is null; |
1254 } | |
1255 | |
1256 int getInsetWidth () { | |
1257 //TODO - wrong | |
1258 return 20; | |
969 } | 1259 } |
970 | 1260 |
971 /** | 1261 /** |
972 * Returns the item at the given, zero-relative index in the | 1262 * Returns the item at the given, zero-relative index in the |
973 * receiver. Throws an exception if the index is out of range. | 1263 * receiver. Throws an exception if the index is out of range. |
987 */ | 1277 */ |
988 public TreeItem getItem (int index) { | 1278 public TreeItem getItem (int index) { |
989 checkWidget (); | 1279 checkWidget (); |
990 int count = getItemCount (); | 1280 int count = getItemCount (); |
991 if (index < 0 || index >= count) error (DWT.ERROR_INVALID_RANGE); | 1281 if (index < 0 || index >= count) error (DWT.ERROR_INVALID_RANGE); |
992 return _getItem (null, index); | 1282 return _getItem (null, index, true); |
993 } | 1283 } |
994 | 1284 |
995 /** | 1285 /** |
996 * Returns the item at the given point in the receiver | 1286 * Returns the item at the given point in the receiver |
997 * or null if no such item exists. The point is in the | 1287 * or null if no such item exists. The point is in the |
1016 * </ul> | 1306 * </ul> |
1017 */ | 1307 */ |
1018 public TreeItem getItem (Point point) { | 1308 public TreeItem getItem (Point point) { |
1019 checkWidget (); | 1309 checkWidget (); |
1020 if (point is null) error (DWT.ERROR_NULL_ARGUMENT); | 1310 if (point is null) error (DWT.ERROR_NULL_ARGUMENT); |
1021 // Rect rect = new Rect (); | 1311 NSOutlineView widget = (NSOutlineView)view; |
1022 // dwt.internal.carbon.Point pt = new dwt.internal.carbon.Point (); | 1312 NSPoint pt = new NSPoint(); |
1023 // OS.SetPt (pt, cast(short) point.x, cast(short) point.y); | 1313 pt.x = point.x; |
1024 // if (0 < lastHittest && lastHittest <= items.length && lastHittestColumn !is 0) { | 1314 pt.y = point.y; |
1025 // TreeItem item = _getItem (lastHittest, false); | 1315 int row = (int)/*64*/widget.rowAtPoint(pt); |
1026 // if (item !is null) { | 1316 if (row is -1) return null; |
1027 // if (OS.GetDataBrowserItemPartBounds (handle, item.id, lastHittestColumn, OS.kDataBrowserPropertyDisclosurePart, rect) is OS.noErr) { | 1317 id id = widget.itemAtRow(row); |
1028 // if (OS.PtInRect (pt, rect)) return null; | 1318 Widget item = display.getWidget (id.id); |
1029 // } | 1319 if (item !is null && item instanceof TreeItem) { |
1030 // if (OS.GetDataBrowserItemPartBounds (handle, item.id, lastHittestColumn, OS.kDataBrowserPropertyEnclosingPart, rect) is OS.noErr) { | 1320 return (TreeItem)item; |
1031 // if (rect.top <= pt.v && pt.v <= rect.bottom) { | 1321 } |
1032 // if ((style & DWT.FULL_SELECTION) !is 0) { | |
1033 // return item; | |
1034 // } else { | |
1035 // return OS.PtInRect (pt, rect) ? item : null; | |
1036 // } | |
1037 // } | |
1038 // } | |
1039 // } | |
1040 // } | |
1041 // //TODO - optimize | |
1042 // for (int i=0; i<items.length; i++) { | |
1043 // TreeItem item = items [i]; | |
1044 // if (item !is null) { | |
1045 // if (OS.GetDataBrowserItemPartBounds (handle, item.id, column_id, OS.kDataBrowserPropertyDisclosurePart, rect) is OS.noErr) { | |
1046 // if (OS.PtInRect (pt, rect)) return null; | |
1047 // } | |
1048 // if (columnCount is 0) { | |
1049 // if (OS.GetDataBrowserItemPartBounds (handle, item.id, column_id, OS.kDataBrowserPropertyEnclosingPart, rect) is OS.noErr) { | |
1050 // if (rect.top <= pt.v && pt.v <= rect.bottom) { | |
1051 // if ((style & DWT.FULL_SELECTION) !is 0) { | |
1052 // return item; | |
1053 // } else { | |
1054 // return OS.PtInRect (pt, rect) ? item : null; | |
1055 // } | |
1056 // } | |
1057 // } | |
1058 // } else { | |
1059 // for (int j = 0; j < columnCount; j++) { | |
1060 // if (OS.GetDataBrowserItemPartBounds (handle, item.id, columns [j].id, OS.kDataBrowserPropertyEnclosingPart, rect) is OS.noErr) { | |
1061 // if (rect.top <= pt.v && pt.v <= rect.bottom) { | |
1062 // if ((style & DWT.FULL_SELECTION) !is 0) { | |
1063 // return item; | |
1064 // } else { | |
1065 // return OS.PtInRect (pt, rect) ? item : null; | |
1066 // } | |
1067 // } | |
1068 // } | |
1069 // } | |
1070 // } | |
1071 // } | |
1072 // } | |
1073 return null; | 1322 return null; |
1074 } | 1323 } |
1075 | 1324 |
1076 /** | 1325 /** |
1077 * Returns the number of items contained in the receiver | 1326 * Returns the number of items contained in the receiver |
1089 public int getItemCount () { | 1338 public int getItemCount () { |
1090 checkWidget (); | 1339 checkWidget (); |
1091 return itemCount; | 1340 return itemCount; |
1092 } | 1341 } |
1093 | 1342 |
1343 int getItemCount (TreeItem item) { | |
1344 return item is null ? itemCount : item.itemCount; | |
1345 } | |
1346 | |
1094 /** | 1347 /** |
1095 * Returns the height of the area which would be used to | 1348 * Returns the height of the area which would be used to |
1096 * display <em>one</em> of the items in the tree. | 1349 * display <em>one</em> of the items in the tree. |
1097 * | 1350 * |
1098 * @return the height of one item | 1351 * @return the height of one item |
1102 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1355 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1103 * </ul> | 1356 * </ul> |
1104 */ | 1357 */ |
1105 public int getItemHeight () { | 1358 public int getItemHeight () { |
1106 checkWidget (); | 1359 checkWidget (); |
1107 return cast(int)(cast(NSTableView)view).rowHeight(); | 1360 return cast(int)(cast(NSOutlineView) view).rowHeight (); |
1108 } | 1361 } |
1109 | 1362 |
1110 /** | 1363 /** |
1111 * Returns a (possibly empty) array of items contained in the | 1364 * Returns a (possibly empty) array of items contained in the |
1112 * receiver that are direct item children of the receiver. These | 1365 * receiver that are direct item children of the receiver. These |
1126 */ | 1379 */ |
1127 public TreeItem [] getItems () { | 1380 public TreeItem [] getItems () { |
1128 checkWidget (); | 1381 checkWidget (); |
1129 TreeItem [] result = new TreeItem [itemCount]; | 1382 TreeItem [] result = new TreeItem [itemCount]; |
1130 for (int i=0; i<itemCount; i++) { | 1383 for (int i=0; i<itemCount; i++) { |
1131 result [i] = _getItem (null, i); | 1384 result [i] = _getItem (null, i, true); |
1132 } | 1385 } |
1133 return result; | 1386 return result; |
1134 } | 1387 } |
1135 | 1388 |
1136 /** | 1389 /** |
1152 * | 1405 * |
1153 * @since 3.1 | 1406 * @since 3.1 |
1154 */ | 1407 */ |
1155 public bool getLinesVisible () { | 1408 public bool getLinesVisible () { |
1156 checkWidget (); | 1409 checkWidget (); |
1157 // if (OS.VERSION >= 0x1040) { | 1410 return ((NSOutlineView) view).usesAlternatingRowBackgroundColors (); |
1158 // int [] attrib = new int [1]; | |
1159 // OS.DataBrowserGetAttributes (handle, attrib); | |
1160 // return (attrib [0] & (OS.kDataBrowserAttributeListViewAlternatingRowColors | OS.kDataBrowserAttributeListViewDrawColumnDividers)) !is 0; | |
1161 // } | |
1162 return false; | |
1163 } | 1411 } |
1164 | 1412 |
1165 /** | 1413 /** |
1166 * Returns the receiver's parent item, which must be a | 1414 * Returns the receiver's parent item, which must be a |
1167 * <code>TreeItem</code> or null when the receiver is a | 1415 * <code>TreeItem</code> or null when the receiver is a |
1195 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1443 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1196 * </ul> | 1444 * </ul> |
1197 */ | 1445 */ |
1198 public TreeItem [] getSelection () { | 1446 public TreeItem [] getSelection () { |
1199 checkWidget (); | 1447 checkWidget (); |
1200 NSOutlineView widget = cast(NSOutlineView)view; | 1448 NSOutlineView widget = cast(NSOutlineView) view; |
1201 if (widget.numberOfSelectedRows() is 0) { | 1449 if (widget.numberOfSelectedRows () is 0) { |
1202 return new TreeItem [0]; | 1450 return new TreeItem [0]; |
1203 } | 1451 } |
1204 NSIndexSet selection = widget.selectedRowIndexes(); | 1452 NSIndexSet selection = widget.selectedRowIndexes (); |
1205 int count = selection.count(); | 1453 int count = (int)/*64*/selection.count (); |
1206 int [] indexBuffer = new int [count]; | 1454 int /*long*/ [] indexBuffer = new int /*long*/ [count]; |
1207 selection.getIndexes(indexBuffer, count, 0); | 1455 selection.getIndexes (indexBuffer, count, 0); |
1208 TreeItem [] result = new TreeItem [count]; | 1456 TreeItem [] result = new TreeItem [count]; |
1209 for (int i=0; i<count; i++) { | 1457 for (int i=0; i<count; i++) { |
1210 id item = widget.itemAtRow(indexBuffer [i]); | 1458 id id = widget.itemAtRow (indexBuffer [i]); |
1211 int jniRef = OS.objc_msgSend(item.id, OS.sel_tag); | 1459 Widget item = display.getWidget (id.id); |
1212 if (jniRef !is -1 && jniRef !is 0) { | 1460 if (item !is null && item instanceof TreeItem) { |
1213 //TODO virtual | 1461 //TODO virtual |
1214 result[i] = cast(TreeItem)OS.JNIGetObject(jniRef); | 1462 result[i] = cast(TreeItem) item; |
1215 } | 1463 } |
1216 } | 1464 } |
1217 return result; | 1465 return result; |
1218 } | 1466 } |
1219 | 1467 |
1227 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1475 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1228 * </ul> | 1476 * </ul> |
1229 */ | 1477 */ |
1230 public int getSelectionCount () { | 1478 public int getSelectionCount () { |
1231 checkWidget (); | 1479 checkWidget (); |
1232 return (cast(NSTableView)view).numberOfSelectedRows(); | 1480 return cast(int)/*64*/(cast(NSOutlineView) view).numberOfSelectedRows (); |
1233 } | 1481 } |
1234 | 1482 |
1235 /** | 1483 /** |
1236 * Returns the column which shows the sort indicator for | 1484 * Returns the column which shows the sort indicator for |
1237 * the receiver. The value may be null if no column shows | 1485 * the receiver. The value may be null if no column shows |
1287 * </ul> | 1535 * </ul> |
1288 * | 1536 * |
1289 * @since 2.1 | 1537 * @since 2.1 |
1290 */ | 1538 */ |
1291 public TreeItem getTopItem () { | 1539 public TreeItem getTopItem () { |
1292 checkWidget(); | 1540 checkWidget (); |
1293 // //TODO - optimize | 1541 // //TODO - optimize |
1294 // Rect rect = new Rect (); | 1542 // Rect rect = new Rect (); |
1295 // int y = getBorder () + getHeaderHeight (); | 1543 // int y = getBorder () + getHeaderHeight (); |
1296 // for (int i=0; i<items.length; i++) { | 1544 // for (int i=0; i<items.length; i++) { |
1297 // TreeItem item = items [i]; | 1545 // TreeItem item = items [i]; |
1303 // } | 1551 // } |
1304 // } | 1552 // } |
1305 return null; | 1553 return null; |
1306 } | 1554 } |
1307 | 1555 |
1556 void highlightSelectionInClipRect(int /*long*/ id, int /*long*/ sel, int /*long*/ rect) { | |
1557 if (!hooks (DWT.EraseItem)) { | |
1558 NSRect clipRect = new NSRect (); | |
1559 OS.memmove (clipRect, rect, NSRect.sizeof); | |
1560 callSuper (id, sel, clipRect); | |
1561 } | |
1562 } | |
1563 | |
1308 /** | 1564 /** |
1309 * Searches the receiver's list starting at the first column | 1565 * Searches the receiver's list starting at the first column |
1310 * (index 0) until a column is found that is equal to the | 1566 * (index 0) until a column is found that is equal to the |
1311 * argument, and returns the index of that column. If no column | 1567 * argument, and returns the index of that column. If no column |
1312 * is found, returns -1. | 1568 * is found, returns -1. |
1363 if (item is items[i]) return i; | 1619 if (item is items[i]) return i; |
1364 } | 1620 } |
1365 return -1; | 1621 return -1; |
1366 } | 1622 } |
1367 | 1623 |
1368 int outlineView_child_ofItem(int outlineView, int index, int ref) { | 1624 bool isTrim (NSView view) { |
1369 TreeItem parent = null; | 1625 if (super.isTrim (view)) return true; |
1370 if (ref !is 0) parent = cast(TreeItem)OS.JNIGetObject(OS.objc_msgSend(ref, OS.sel_tag)); | 1626 return view.id_ is headerView.id_; |
1371 TreeItem item = _getItem(parent, index); | 1627 } |
1628 | |
1629 int /*long*/ outlineView_child_ofItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ index, int /*long*/ itemID) { | |
1630 TreeItem parent = (TreeItem) display.getWidget (itemID); | |
1631 TreeItem item = _getItem (parent, (int)/*64*/index, true); | |
1632 checkData (item, false); | |
1372 return item.handle.id; | 1633 return item.handle.id; |
1373 } | 1634 } |
1374 | 1635 |
1375 int outlineView_objectValueForTableColumn_byItem(int outlineView, int tableColumn, int ref) { | 1636 void outlineView_didClickTableColumn (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn) { |
1376 TreeItem item = cast(TreeItem)OS.JNIGetObject(OS.objc_msgSend(ref, OS.sel_tag)); | 1637 TreeColumn column = getColumn (new id (tableColumn)); |
1638 column.postEvent (DWT.Selection); | |
1639 } | |
1640 | |
1641 int /*long*/ outlineView_objectValueForTableColumn_byItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn, int /*long*/ itemID) { | |
1642 TreeItem item = (TreeItem) display.getWidget (itemID); | |
1377 if (checkColumn !is null && tableColumn is checkColumn.id) { | 1643 if (checkColumn !is null && tableColumn is checkColumn.id) { |
1378 NSNumber value; | 1644 NSNumber value; |
1379 if (item.checked && item.grayed) { | 1645 if (item.checked && item.grayed) { |
1380 value = NSNumber.numberWithInt(OS.NSMixedState); | 1646 value = NSNumber.numberWithInt (OS.NSMixedState); |
1381 } else { | 1647 } else { |
1382 value = NSNumber.numberWithInt(item.checked ? OS.NSOnState : OS.NSOffState); | 1648 value = NSNumber.numberWithInt (item.checked ? OS.NSOnState : OS.NSOffState); |
1383 } | 1649 } |
1384 return value.id; | 1650 return value.id; |
1385 } | 1651 } |
1386 for (int i=0; i<columnCount; i++) { | 1652 for (int i=0; i<columnCount; i++) { |
1387 if (columns [i].nsColumn.id is tableColumn) { | 1653 if (columns [i].nsColumn.id is tableColumn) { |
1388 return item.createString(i).id; | 1654 return item.createString (i).id; |
1389 } | 1655 } |
1390 } | 1656 } |
1391 return item.createString(0).id; | 1657 return item.createString (0).id; |
1392 } | 1658 } |
1393 | 1659 |
1394 bool outlineView_isItemExpandable(int outlineView, int ref) { | 1660 bool outlineView_isItemExpandable (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) { |
1395 if (ref is 0) return true; | 1661 if (item is 0) return true; |
1396 return (cast(TreeItem)OS.JNIGetObject(OS.objc_msgSend(ref, OS.sel_tag))).itemCount !is 0; | 1662 return (cast(TreeItem) display.getWidget (item)).itemCount !is 0; |
1397 } | 1663 } |
1398 | 1664 |
1399 int outlineView_numberOfChildrenOfItem(int outlineView, int ref) { | 1665 int /*long*/ outlineView_numberOfChildrenOfItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) { |
1400 if (ref is 0) return itemCount; | 1666 if (item is 0) return itemCount; |
1401 return (cast(TreeItem)OS.JNIGetObject(OS.objc_msgSend(ref, OS.sel_tag))).itemCount; | 1667 return (cast(TreeItem) display.getWidget (item)).itemCount; |
1402 } | 1668 } |
1403 | 1669 |
1404 void outlineView_willDisplayCell_forTableColumn_item(int outlineView, int cell, int tableColumn, int ref) { | 1670 void outlineView_willDisplayCell_forTableColumn_item (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ cell, int /*long*/ tableColumn, int /*long*/ itemID) { |
1405 if (checkColumn !is null && tableColumn is checkColumn.id) return; | 1671 if (checkColumn !is null && tableColumn is checkColumn.id) return; |
1406 TreeItem item = cast(TreeItem)OS.JNIGetObject(OS.objc_msgSend(ref, OS.sel_tag)); | 1672 TreeItem item = cast(TreeItem) display.getWidget(itemID); |
1407 Image image = item.image; | 1673 Image image = item.image; |
1674 int columnIndex = 0; | |
1408 for (int i=0; i<columnCount; i++) { | 1675 for (int i=0; i<columnCount; i++) { |
1409 if (columns [i].nsColumn.id is tableColumn) { | 1676 if (columns [i].nsColumn.id is tableColumn) { |
1410 image = item.getImage(i); | 1677 image = item.getImage (i); |
1411 } | 1678 columnIndex = i; |
1412 } | 1679 } |
1413 NSBrowserCell browserCell = new NSBrowserCell(cell); | 1680 } |
1414 browserCell.setImage(image !is null ? image.handle : null); | 1681 NSBrowserCell browserCell = new NSBrowserCell (cell); |
1415 } | 1682 browserCell.setImage (image !is null ? image.handle : null); |
1416 | 1683 browserCell.setFont (item.getFont (columnIndex).handle); |
1417 void outlineViewSelectionDidChange(int notification) { | 1684 |
1685 if (hooks (DWT.MeasureItem)) { | |
1686 NSOutlineView view = (NSOutlineView)this.view; | |
1687 int nsColumnIndex = (int)/*64*/view.columnWithIdentifier (new id (tableColumn)); | |
1688 int rowIndex = (int)/*64*/view.rowForItem (new id (itemID)); | |
1689 NSRect rect = view.frameOfCellAtColumn (nsColumnIndex, rowIndex); | |
1690 NSRect contentRect = browserCell.titleRectForBounds (rect); | |
1691 NSSize contentSize = browserCell.cellSizeForBounds (rect); | |
1692 | |
1693 GCData data = new GCData (); | |
1694 data.paintRect = view.frame (); | |
1695 GC gc = GC.cocoa_new (this, data); | |
1696 gc.setFont (item.getFont (columnIndex)); | |
1697 int rowHeight = (int)view.rowHeight (); | |
1698 Event event = new Event (); | |
1699 event.item = item; | |
1700 event.gc = gc; | |
1701 event.index = columnIndex; | |
1702 event.x = (int)contentRect.x; | |
1703 event.y = (int)contentRect.y; | |
1704 event.width = (int)Math.ceil (contentSize.width); | |
1705 event.height = rowHeight; | |
1706 sendEvent (DWT.MeasureItem, event); | |
1707 gc.dispose (); | |
1708 if (isDisposed ()) return; | |
1709 if (rowHeight < event.height) { | |
1710 view.setRowHeight (event.height); | |
1711 } | |
1712 if (columnCount is 0) { | |
1713 int change = event.width - (item.customWidth !is -1 ? item.customWidth : (int)Math.ceil (contentSize.width)); | |
1714 if (item.customWidth !is -1 || event.width !is (int)Math.ceil (contentSize.width)) { | |
1715 item.customWidth = event.width; | |
1716 } | |
1717 if (change !is 0) setScrollWidth (item, false, false); | |
1718 } | |
1719 } | |
1720 } | |
1721 | |
1722 void outlineViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { | |
1723 NSNotification notification = new NSNotification (aNotification); | |
1724 NSDictionary userInfo = notification.userInfo (); | |
1725 id nsOldIndex = userInfo.valueForKey (NSString.stringWith ("NSOldColumn")); //$NON-NLS-1$ | |
1726 id nsNewIndex = userInfo.valueForKey (NSString.stringWith ("NSNewColumn")); //$NON-NLS-1$ | |
1727 int oldIndex = new NSNumber (nsOldIndex).intValue (); | |
1728 int newIndex = new NSNumber (nsNewIndex).intValue (); | |
1729 int startIndex = Math.min (oldIndex, newIndex); | |
1730 int endIndex = Math.max (oldIndex, newIndex); | |
1731 NSOutlineView outlineView = (NSOutlineView)view; | |
1732 NSArray nsColumns = outlineView.tableColumns (); | |
1733 for (int i = startIndex; i <= endIndex; i++) { | |
1734 id columnId = nsColumns.objectAtIndex (i); | |
1735 TreeColumn column = getColumn (columnId); | |
1736 if (column !is null) { | |
1737 column.sendEvent (DWT.Move); | |
1738 if (isDisposed ()) return; | |
1739 } | |
1740 } | |
1741 } | |
1742 | |
1743 void outlineViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { | |
1744 NSNotification notification = new NSNotification (aNotification); | |
1745 NSDictionary userInfo = notification.userInfo (); | |
1746 id columnId = userInfo.valueForKey (NSString.stringWith ("NSTableColumn")); //$NON-NLS-1$ | |
1747 TreeColumn column = getColumn (columnId); | |
1748 if (column is null) return; /* either CHECK column or firstColumn in 0-column Tree */ | |
1749 | |
1750 column.sendEvent (DWT.Resize); | |
1751 if (isDisposed ()) return; | |
1752 | |
1753 NSOutlineView outlineView = (NSOutlineView)view; | |
1754 int index = (int)/*64*/outlineView.columnWithIdentifier (columnId); | |
1755 if (index is -1) return; /* column was disposed in Resize callback */ | |
1756 | |
1757 NSArray nsColumns = outlineView.tableColumns (); | |
1758 int columnCount = (int)/*64*/outlineView.numberOfColumns (); | |
1759 for (int i = index + 1; i < columnCount; i++) { | |
1760 columnId = nsColumns.objectAtIndex (i); | |
1761 column = getColumn (columnId); | |
1762 if (column !is null) { | |
1763 column.sendEvent (DWT.Move); | |
1764 if (isDisposed ()) return; | |
1765 } | |
1766 } | |
1767 } | |
1768 | |
1769 void outlineViewItemDidExpand (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) { | |
1770 NSNotification nsNotification = new NSNotification (notification); | |
1771 NSDictionary info = nsNotification.userInfo (); | |
1772 NSString key = NSString.stringWith ("NSObject"); //$NON-NLS-1$ | |
1773 int /*long*/ itemHandle = info.objectForKey (key).id; | |
1774 TreeItem item = (TreeItem)display.getWidget (itemHandle); | |
1775 setScrollWidth (item.getItems (), true, true); | |
1776 } | |
1777 | |
1778 void outlineViewSelectionDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) { | |
1418 if (ignoreSelect) return; | 1779 if (ignoreSelect) return; |
1419 NSOutlineView widget = cast(NSOutlineView)view; | 1780 NSOutlineView widget = cast(NSOutlineView) view; |
1420 int row = widget.selectedRow(); | 1781 int row = (int)/*64*/widget.selectedRow (); |
1421 if(row is -1) | 1782 if (row is -1) |
1422 postEvent(DWT.Selection); | 1783 postEvent (DWT.Selection); |
1423 else { | 1784 else { |
1424 id _id = widget.itemAtRow(row); | 1785 id _id = widget.itemAtRow (row); |
1425 TreeItem item = cast(TreeItem)OS.JNIGetObject(OS.objc_msgSend(_id.id, OS.sel_tag)); | 1786 TreeItem item = cast(TreeItem) display.getWidget (_id.id); |
1426 Event event = new Event(); | 1787 Event event = new Event (); |
1427 event.item = item; | 1788 event.item = item; |
1428 event.index = row; | 1789 event.index = row; |
1429 postEvent(DWT.Selection, event); | 1790 postEvent (DWT.Selection, event); |
1430 } | 1791 } |
1431 } | 1792 } |
1432 | 1793 |
1433 bool outlineView_shouldCollapseItem(int outlineView, int ref) { | 1794 bool outlineView_shouldCollapseItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ itemID) { |
1795 TreeItem item = (TreeItem) display.getWidget (itemID); | |
1434 if (!ignoreExpand) { | 1796 if (!ignoreExpand) { |
1435 TreeItem item = cast(TreeItem)OS.JNIGetObject(OS.objc_msgSend(ref, OS.sel_tag)); | 1797 Event event = new Event (); |
1436 Event event = new Event(); | |
1437 event.item = item; | 1798 event.item = item; |
1438 sendEvent(DWT.Collapse, event); | 1799 sendEvent (DWT.Collapse, event); |
1439 item.expanded = false; | 1800 item.expanded = false; |
1440 } | 1801 ignoreExpand = true; |
1441 return true; | 1802 ((NSOutlineView) view).collapseItem (item.handle); |
1442 } | 1803 ignoreExpand = false; |
1443 | 1804 return false; |
1444 bool outlineView_shouldExpandItem(int outlineView, int ref) { | 1805 } |
1806 return !item.expanded; | |
1807 } | |
1808 | |
1809 bool outlineView_shouldExpandItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ itemID) { | |
1810 final TreeItem item = (TreeItem) display.getWidget (itemID); | |
1445 if (!ignoreExpand) { | 1811 if (!ignoreExpand) { |
1446 TreeItem item = cast(TreeItem)OS.JNIGetObject(OS.objc_msgSend(ref, OS.sel_tag)); | 1812 Event event = new Event (); |
1447 Event event = new Event(); | |
1448 event.item = item; | 1813 event.item = item; |
1449 sendEvent(DWT.Expand, event); | 1814 sendEvent (DWT.Expand, event); |
1450 item.expanded = true; | 1815 item.expanded = true; |
1451 } | 1816 ignoreExpand = true; |
1452 return true; | 1817 ((NSOutlineView) view).expandItem (item.handle); |
1453 } | 1818 ignoreExpand = false; |
1454 | 1819 return false; |
1455 void outlineView_setObjectValue_forTableColumn_byItem(int outlineView, int object, int tableColumn, int ref) { | 1820 } |
1456 TreeItem item = cast(TreeItem)OS.JNIGetObject(OS.objc_msgSend(ref, OS.sel_tag)); | 1821 return item.expanded; |
1822 } | |
1823 | |
1824 void outlineView_setObjectValue_forTableColumn_byItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ object, int /*long*/ tableColumn, int /*long*/ itemID) { | |
1457 if (checkColumn !is null && tableColumn is checkColumn.id) { | 1825 if (checkColumn !is null && tableColumn is checkColumn.id) { |
1826 TreeItem item = (TreeItem) display.getWidget (itemID); | |
1458 item.checked = !item.checked; | 1827 item.checked = !item.checked; |
1459 Event event = new Event(); | 1828 Event event = new Event (); |
1460 event.detail = DWT.CHECK; | 1829 event.detail = DWT.CHECK; |
1461 event.item = item; | 1830 event.item = item; |
1462 postEvent(DWT.Selection, event); | 1831 postEvent (DWT.Selection, event); |
1463 } | 1832 NSOutlineView view = (NSOutlineView)this.view; |
1833 int rowIndex = (int)/*64*/view.rowForItem (new id (itemID)); | |
1834 NSRect rect = view.rectOfRow (rowIndex); | |
1835 view.setNeedsDisplayInRect (rect); | |
1836 } | |
1837 } | |
1838 | |
1839 void register () { | |
1840 super.register (); | |
1841 display.addWidget (headerView, this); | |
1842 display.addWidget (dataCell, this); | |
1464 } | 1843 } |
1465 | 1844 |
1466 void releaseChildren (bool destroy) { | 1845 void releaseChildren (bool destroy) { |
1467 for (int i=0; i<items.length; i++) { | 1846 for (int i=0; i<items.length; i++) { |
1468 TreeItem item = items [i]; | 1847 TreeItem item = items [i]; |
1483 super.releaseChildren (destroy); | 1862 super.releaseChildren (destroy); |
1484 } | 1863 } |
1485 | 1864 |
1486 void releaseHandle () { | 1865 void releaseHandle () { |
1487 super.releaseHandle (); | 1866 super.releaseHandle (); |
1488 if (headerView !is null) headerView.release(); | 1867 if (headerView !is null) headerView.release (); |
1489 headerView = null; | 1868 headerView = null; |
1490 if (firstColumn !is null) firstColumn.release(); | 1869 if (firstColumn !is null) firstColumn.release (); |
1491 firstColumn = null; | 1870 firstColumn = null; |
1492 if (checkColumn !is null) checkColumn.release(); | 1871 if (checkColumn !is null) checkColumn.release (); |
1493 checkColumn = null; | 1872 checkColumn = null; |
1873 if (dataCell !is null) dataCell.release (); | |
1874 dataCell = null; | |
1494 } | 1875 } |
1495 | 1876 |
1496 void releaseWidget () { | 1877 void releaseWidget () { |
1497 super.releaseWidget (); | 1878 super.releaseWidget (); |
1498 //release handle | 1879 //release handle |
1513 TreeItem item = items [i]; | 1894 TreeItem item = items [i]; |
1514 if (item !is null && !item.isDisposed ()) item.release (false); | 1895 if (item !is null && !item.isDisposed ()) item.release (false); |
1515 } | 1896 } |
1516 items = new TreeItem [4]; | 1897 items = new TreeItem [4]; |
1517 itemCount = 0; | 1898 itemCount = 0; |
1518 (cast(NSOutlineView)view).reloadItem_(null); | 1899 (cast(NSOutlineView) view).reloadItem (null); |
1519 //(cast(NSTableView)view).noteNumberOfRowsChanged(); | |
1520 // setScrollWidth (true); | |
1521 } | 1900 } |
1522 | 1901 |
1523 /** | 1902 /** |
1524 * Removes the listener from the collection of listeners who will | 1903 * Removes the listener from the collection of listeners who will |
1525 * be notified when the user changes the receiver's selection. | 1904 * be notified when the user changes the receiver's selection. |
1559 * </ul> | 1938 * </ul> |
1560 * | 1939 * |
1561 * @see TreeListener | 1940 * @see TreeListener |
1562 * @see #addTreeListener | 1941 * @see #addTreeListener |
1563 */ | 1942 */ |
1564 public void removeTreeListener(TreeListener listener) { | 1943 public void removeTreeListener (TreeListener listener) { |
1565 checkWidget (); | 1944 checkWidget (); |
1566 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | 1945 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); |
1567 if (eventTable is null) return; | 1946 if (eventTable is null) return; |
1568 eventTable.unhook (DWT.Expand, listener); | 1947 eventTable.unhook (DWT.Expand, listener); |
1569 eventTable.unhook (DWT.Collapse, listener); | 1948 eventTable.unhook (DWT.Collapse, listener); |
1587 * </ul> | 1966 * </ul> |
1588 */ | 1967 */ |
1589 public void setInsertMark (TreeItem item, bool before) { | 1968 public void setInsertMark (TreeItem item, bool before) { |
1590 checkWidget (); | 1969 checkWidget (); |
1591 if (item !is null) { | 1970 if (item !is null) { |
1592 if (item.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT); | 1971 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); |
1593 } | 1972 } |
1594 } | 1973 } |
1595 | 1974 |
1596 /** | 1975 /** |
1597 * Selects all of the items in the receiver. | 1976 * Selects all of the items in the receiver. |
1605 * </ul> | 1984 * </ul> |
1606 */ | 1985 */ |
1607 public void selectAll () { | 1986 public void selectAll () { |
1608 checkWidget (); | 1987 checkWidget (); |
1609 if ((style & DWT.SINGLE) !is 0) return; | 1988 if ((style & DWT.SINGLE) !is 0) return; |
1610 NSTableView widget = cast(NSTableView)view; | 1989 NSOutlineView widget = cast(NSOutlineView) view; |
1611 ignoreSelect = true; | 1990 ignoreSelect = true; |
1612 widget.selectAll(null); | 1991 widget.selectAll (null); |
1613 ignoreSelect = false; | 1992 ignoreSelect = false; |
1614 } | 1993 } |
1615 | 1994 |
1995 /** | |
1996 * Selects an item in the receiver. If the item was already | |
1997 * selected, it remains selected. | |
1998 * | |
1999 * @param item the item to be selected | |
2000 * | |
2001 * @exception IllegalArgumentException <ul> | |
2002 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
2003 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
2004 * </ul> | |
2005 * @exception DWTException <ul> | |
2006 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2007 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2008 * </ul> | |
2009 * | |
2010 * @since 3.4 | |
2011 */ | |
1616 public void select (TreeItem item) { | 2012 public void select (TreeItem item) { |
1617 checkWidget (); | 2013 checkWidget (); |
1618 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | 2014 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); |
1619 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | 2015 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); |
1620 // showItem (item, false); | 2016 showItem (item); |
1621 // ignoreSelect = true; | 2017 NSOutlineView outlineView = (NSOutlineView) view; |
1622 // /* | 2018 outlineView.selectRow (outlineView.rowForItem (item.handle), false); |
1623 // * Bug in the Macintosh. When the DataBroswer selection flags includes | |
1624 // * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne, | |
1625 // * two items are selected when SetDataBrowserSelectedItems() is called | |
1626 // * with kDataBrowserItemsAssign to assign a new seletion despite the fact | |
1627 // * that kDataBrowserSelectOnlyOne was specified. The fix is to save and | |
1628 // * restore kDataBrowserNeverEmptySelectionSet around each call to | |
1629 // * SetDataBrowserSelectedItems(). | |
1630 // */ | |
1631 // int [] selectionFlags = null; | |
1632 // if ((style & DWT.SINGLE) !is 0) { | |
1633 // selectionFlags = new int [1]; | |
1634 // OS.GetDataBrowserSelectionFlags (handle, selectionFlags); | |
1635 // OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet); | |
1636 // } | |
1637 // OS.SetDataBrowserSelectedItems (handle, 1, new int [] {item.id}, OS.kDataBrowserItemsAssign); | |
1638 // if ((style & DWT.SINGLE) !is 0) { | |
1639 // OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]); | |
1640 // } | |
1641 // ignoreSelect = false; | |
1642 } | 2019 } |
1643 | 2020 |
1644 void sendDoubleSelection() { | 2021 void sendDoubleSelection() { |
1645 postEvent (DWT.DefaultSelection); | 2022 postEvent (DWT.DefaultSelection); |
2023 } | |
2024 | |
2025 bool sendKeyEvent (NSEvent nsEvent, int type) { | |
2026 bool result = super.sendKeyEvent (nsEvent, type); | |
2027 if (!result) return result; | |
2028 if (type !is DWT.KeyDown) return result; | |
2029 short keyCode = nsEvent.keyCode (); | |
2030 switch (keyCode) { | |
2031 case 76: /* KP Enter */ | |
2032 case 36: { /* Return */ | |
2033 postEvent (DWT.DefaultSelection); | |
2034 break; | |
2035 } | |
2036 } | |
2037 return result; | |
2038 } | |
2039 | |
2040 void setBackground (float [] color) { | |
2041 super.setBackground (color); | |
2042 NSColor nsColor; | |
2043 if (color is null) { | |
2044 nsColor = null; | |
2045 } else { | |
2046 nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1); | |
2047 } | |
2048 ((NSOutlineView) view).setBackgroundColor (nsColor); | |
1646 } | 2049 } |
1647 | 2050 |
1648 /** | 2051 /** |
1649 * Sets the order that the items in the receiver should | 2052 * Sets the order that the items in the receiver should |
1650 * be displayed in to the given argument which is described | 2053 * be displayed in to the given argument which is described |
1686 if (seen [index]) error (DWT.ERROR_INVALID_ARGUMENT); | 2089 if (seen [index]) error (DWT.ERROR_INVALID_ARGUMENT); |
1687 seen [index] = true; | 2090 seen [index] = true; |
1688 if (order [i] !is oldOrder [i]) reorder = true; | 2091 if (order [i] !is oldOrder [i]) reorder = true; |
1689 } | 2092 } |
1690 if (reorder) { | 2093 if (reorder) { |
1691 int [] disclosure = new int [1]; | 2094 NSOutlineView outlineView = (NSOutlineView)view; |
1692 bool [] expandableRows = new bool [1]; | |
1693 // OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, expandableRows); | |
1694 TreeColumn firstColumn = columns [order [0]]; | |
1695 // if (disclosure [0] !is firstColumn.id) { | |
1696 // OS.SetDataBrowserListViewDisclosureColumn (handle, firstColumn.id, expandableRows [0]); | |
1697 // } | |
1698 int x = 0; | |
1699 short [] width = new short [1]; | |
1700 int [] oldX = new int [oldOrder.length]; | 2095 int [] oldX = new int [oldOrder.length]; |
2096 int check = (style & DWT.CHECK) !is 0 ? 1 : 0; | |
1701 for (int i=0; i<oldOrder.length; i++) { | 2097 for (int i=0; i<oldOrder.length; i++) { |
1702 int index = oldOrder [i]; | 2098 int index = oldOrder[i]; |
1703 TreeColumn column = columns [index]; | 2099 oldX [index] = (int)outlineView.rectOfColumn (i + check).x; |
1704 oldX [index] = x; | 2100 } |
1705 // OS.GetDataBrowserTableViewNamedColumnWidth(handle, column.id, width); | |
1706 x += width [0]; | |
1707 } | |
1708 x = 0; | |
1709 int [] newX = new int [order.length]; | 2101 int [] newX = new int [order.length]; |
1710 for (int i=0; i<order.length; i++) { | 2102 for (int i=0; i<order.length; i++) { |
1711 int index = order [i]; | 2103 int index = order [i]; |
1712 TreeColumn column = columns [index]; | 2104 TreeColumn column = columns[index]; |
1713 int position = (style & DWT.CHECK) !is 0 ? i + 1 : i; | 2105 int oldIndex = outlineView.columnWithIdentifier (column.nsColumn); |
1714 // OS.SetDataBrowserTableViewColumnPosition(handle, column.id, position); | 2106 int newIndex = i + check; |
1715 // column.lastPosition = position; | 2107 outlineView.moveColumn (oldIndex, newIndex); |
1716 newX [index] = x; | 2108 newX [index] = (int)outlineView.rectOfColumn (newIndex).x; |
1717 // OS.GetDataBrowserTableViewNamedColumnWidth(handle, column.id, width); | 2109 } |
1718 x += width [0]; | 2110 |
1719 } | |
1720 TreeColumn[] newColumns = new TreeColumn [columnCount]; | 2111 TreeColumn[] newColumns = new TreeColumn [columnCount]; |
1721 System.arraycopy (columns, 0, newColumns, 0, columnCount); | 2112 System.arraycopy (columns, 0, newColumns, 0, columnCount); |
1722 for (int i=0; i<columnCount; i++) { | 2113 for (int i=0; i<columnCount; i++) { |
1723 TreeColumn column = newColumns [i]; | 2114 TreeColumn column = newColumns [i]; |
1724 if (!column.isDisposed ()) { | 2115 if (!column.isDisposed ()) { |
1728 } | 2119 } |
1729 } | 2120 } |
1730 } | 2121 } |
1731 } | 2122 } |
1732 | 2123 |
2124 void setFont(NSFont font) { | |
2125 super.setFont (font); | |
2126 if (!hooks (DWT.MeasureItem)) { | |
2127 float ascent = font.ascender (); | |
2128 float descent = -font.descender () + font.leading (); | |
2129 ((NSOutlineView)view).setRowHeight ((int)Math.ceil (ascent + descent) + 1); | |
2130 } else { | |
2131 view.setNeedsDisplay (true); | |
2132 } | |
2133 } | |
2134 | |
1733 /** | 2135 /** |
1734 * Marks the receiver's header as visible if the argument is <code>true</code>, | 2136 * Marks the receiver's header as visible if the argument is <code>true</code>, |
1735 * and marks it invisible otherwise. | 2137 * and marks it invisible otherwise. |
1736 * <p> | 2138 * <p> |
1737 * If one of the receiver's ancestors is not visible or some | 2139 * If one of the receiver's ancestors is not visible or some |
1748 * | 2150 * |
1749 * @since 3.1 | 2151 * @since 3.1 |
1750 */ | 2152 */ |
1751 public void setHeaderVisible (bool show) { | 2153 public void setHeaderVisible (bool show) { |
1752 checkWidget (); | 2154 checkWidget (); |
1753 (cast(NSTableView)view).setHeaderView (show ? headerView : null); | 2155 (cast(NSOutlineView) view).setHeaderView (show ? headerView : null); |
1754 } | 2156 } |
1755 | 2157 |
1756 /** | 2158 /** |
1757 * Sets the number of root-level items contained in the receiver. | 2159 * Sets the number of root-level items contained in the receiver. |
1758 * | 2160 * |
1770 count = Math.max (0, count); | 2172 count = Math.max (0, count); |
1771 setItemCount (null, count); | 2173 setItemCount (null, count); |
1772 } | 2174 } |
1773 | 2175 |
1774 void setItemCount (TreeItem parentItem, int count) { | 2176 void setItemCount (TreeItem parentItem, int count) { |
1775 // int itemCount = getItemCount (parentItem); | 2177 int itemCount = getItemCount (parentItem); |
1776 // if (count is itemCount) return; | 2178 if (count is itemCount) return; |
1777 // setRedraw (false); | 2179 TreeItem [] children = parentItem is null ? items : parentItem.items; |
1778 // int [] top = new int [1], left = new int [1]; | 2180 if (count < itemCount) { |
1779 // OS.GetDataBrowserScrollPosition (handle, top, left); | 2181 for (int index = count; index < itemCount; index ++) { |
1780 // DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); | 2182 TreeItem item = children [index]; |
1781 // OS.GetDataBrowserCallbacks (handle, callbacks); | 2183 if (item !is null && !item.isDisposed()) item.release (false); |
1782 // callbacks.v1_itemNotificationCallback = 0; | 2184 } |
1783 // callbacks.v1_itemCompareCallback = 0; | 2185 } |
1784 // OS.SetDataBrowserCallbacks (handle, callbacks); | 2186 if (count > itemCount) { |
1785 // int[] ids = parentItem is null ? childIds : parentItem.childIds; | 2187 if ((getStyle() & DWT.VIRTUAL) is 0) { |
1786 // if (count < itemCount) { | 2188 for (int i=itemCount; i<count; i++) { |
1787 // for (int index = ids.length - 1; index >= count; index--) { | 2189 new TreeItem (this, parentItem, DWT.NONE, i, true); |
1788 // int id = ids [index]; | 2190 } |
1789 // if (id !is 0) { | 2191 return; |
1790 // TreeItem item = _getItem (id, false); | 2192 } |
1791 // if (item !is null && !item.isDisposed ()) { | 2193 } |
1792 // item.dispose (); | 2194 int length = Math.max (4, (count + 3) / 4 * 4); |
1793 // } else { | 2195 TreeItem [] newItems = new TreeItem [length]; |
1794 // if (parentItem is null || parentItem.getExpanded ()) { | 2196 if (children !is null) { |
1795 // if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, 1, new int [] {id}, 0) !is OS.noErr) { | 2197 System.arraycopy (children, 0, newItems, 0, Math.min (count, itemCount)); |
1796 // error (DWT.ERROR_ITEM_NOT_REMOVED); | 2198 } |
1797 // break; | 2199 children = newItems; |
1798 // } | 2200 if (parentItem is null) { |
1799 // visibleCount--; | 2201 this.items = newItems; |
1800 // } | 2202 this.itemCount = count; |
1801 // } | 2203 } else { |
1802 // } | 2204 parentItem.items = newItems; |
1803 // } | 2205 parentItem.itemCount = count; |
1804 // //TODO - move shrink to paint event | 2206 } |
1805 // // shrink items array | 2207 NSOutlineView widget = (NSOutlineView) view; |
1806 // int lastIndex = items.length; | 2208 widget.reloadItem (parentItem !is null ? parentItem.handle : null, true); |
1807 // for (int i=items.length; i>0; i--) { | 2209 widget.noteNumberOfRowsChanged(); |
1808 // if (items [i-1] !is null) { | |
1809 // lastIndex = i; | |
1810 // break; | |
1811 // } | |
1812 // } | |
1813 // if (lastIndex < items.length - 4) { | |
1814 // int length = Math.max (4, (lastIndex + 3) / 4 * 4); | |
1815 // TreeItem [] newItems = new TreeItem [length]; | |
1816 // System.arraycopy(items, 0, newItems, 0, Math.min(items.length, lastIndex)); | |
1817 // } | |
1818 // } | |
1819 // | |
1820 // if (parentItem !is null) parentItem.itemCount = count; | |
1821 // int length = Math.max (4, (count + 3) / 4 * 4); | |
1822 // int [] newIds = new int [length]; | |
1823 // if (ids !is null) { | |
1824 // System.arraycopy (ids, 0, newIds, 0, Math.min (count, itemCount)); | |
1825 // } | |
1826 // ids = newIds; | |
1827 // if (parentItem is null) { | |
1828 // childIds = newIds; | |
1829 // } else { | |
1830 // parentItem.childIds = newIds; | |
1831 // } | |
1832 // | |
1833 // if (count > itemCount) { | |
1834 // if ((getStyle() & DWT.VIRTUAL) is 0) { | |
1835 // int delta = Math.max (4, (count - itemCount + 3) / 4 * 4); | |
1836 // TreeItem [] newItems = new TreeItem [items.length + delta]; | |
1837 // System.arraycopy (items, 0, newItems, 0, items.length); | |
1838 // items = newItems; | |
1839 // for (int i=itemCount; i<count; i++) { | |
1840 // items [i] = new TreeItem (this, parentItem, DWT.NONE, i, true); | |
1841 // } | |
1842 // } else { | |
1843 // if (parentItem is null || parentItem.getExpanded ()) { | |
1844 // int parentID = parentItem is null ? OS.kDataBrowserNoItem : parentItem.id; | |
1845 // int [] addIds = _getIds (count - itemCount); | |
1846 // if (OS.AddDataBrowserItems (handle, parentID, addIds.length, addIds, OS.kDataBrowserItemNoProperty) !is OS.noErr) { | |
1847 // error (DWT.ERROR_ITEM_NOT_ADDED); | |
1848 // } | |
1849 // visibleCount += (count - itemCount); | |
1850 // System.arraycopy (addIds, 0, ids, itemCount, addIds.length); | |
1851 // } | |
1852 // } | |
1853 // } | |
1854 // | |
1855 // callbacks.v1_itemNotificationCallback = display.itemNotificationProc; | |
1856 // callbacks.v1_itemCompareCallback = display.itemCompareProc; | |
1857 // OS.SetDataBrowserCallbacks (handle, callbacks); | |
1858 // setRedraw (true); | |
1859 // if (itemCount is 0 && parentItem !is null) parentItem.redraw (OS.kDataBrowserNoItem); | |
1860 } | 2210 } |
1861 | 2211 |
1862 /*public*/ void setItemHeight (int itemHeight) { | 2212 /*public*/ void setItemHeight (int itemHeight) { |
1863 checkWidget (); | 2213 checkWidget (); |
1864 if (itemHeight < -1) error (DWT.ERROR_INVALID_ARGUMENT); | 2214 if (itemHeight < -1) error (DWT.ERROR_INVALID_ARGUMENT); |
1899 * | 2249 * |
1900 * @since 3.1 | 2250 * @since 3.1 |
1901 */ | 2251 */ |
1902 public void setLinesVisible (bool show) { | 2252 public void setLinesVisible (bool show) { |
1903 checkWidget (); | 2253 checkWidget (); |
1904 (cast(NSTableView)view).setUsesAlternatingRowBackgroundColors(show); | 2254 (cast(NSOutlineView) view).setUsesAlternatingRowBackgroundColors (show); |
1905 } | 2255 } |
1906 | 2256 |
1907 public void setRedraw (bool redraw) { | 2257 public void setRedraw (bool redraw) { |
1908 checkWidget(); | 2258 checkWidget (); |
1909 super.setRedraw (redraw); | 2259 super.setRedraw (redraw); |
1910 if (redraw && drawCount is 0) { | 2260 if (redraw && drawCount is 0) { |
1911 setScrollWidth (true); | 2261 setScrollWidth (); |
1912 } | 2262 } |
1913 } | 2263 } |
1914 | 2264 |
1915 bool setScrollWidth (TreeItem item) { | 2265 bool setScrollWidth () { |
1916 // if (ignoreRedraw || drawCount !is 0) return false; | 2266 return setScrollWidth (items, true, true); |
2267 } | |
2268 | |
2269 bool setScrollWidth (TreeItem item, bool recurse, bool callMeasureItem) { | |
2270 return setScrollWidth (new TreeItem[] {item}, recurse, callMeasureItem); | |
2271 } | |
2272 | |
2273 bool setScrollWidth (TreeItem[] items, bool recurse, bool callMeasureItem) { | |
1917 if (columnCount !is 0) return false; | 2274 if (columnCount !is 0) return false; |
1918 // TreeItem parentItem = item.parentItem; | 2275 // if (currentItem !is null) { |
1919 // if (parentItem !is null && !parentItem._getExpanded ()) return false; | 2276 // if (currentItem !is item) fixScrollWidth = true; |
1920 // GC gc = new GC (this); | 2277 // return false; |
1921 // int newWidth = item.calculateWidth (0, gc); | |
1922 // gc.dispose (); | |
1923 // newWidth += getInsetWidth (column_id, false); | |
1924 // short [] width = new short [1]; | |
1925 // OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width); | |
1926 // if (width [0] < newWidth) { | |
1927 // OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, cast(short) newWidth); | |
1928 // return true; | |
1929 // } | 2278 // } |
1930 // firstColumn.setWidth(400); | 2279 if (/*ignoreRedraw ||*/ drawCount !is 0) return false; |
2280 int newWidth = 0; | |
2281 GC gc = new GC (this); | |
2282 for (int i = 0; i < items.length; i++) { | |
2283 TreeItem item = items[i]; | |
2284 if (item !is null && !item.isDisposed ()) { | |
2285 newWidth = Math.max (newWidth, item.calculateWidth (0, gc, recurse, callMeasureItem)); | |
2286 if (isDisposed ()) { | |
2287 gc.dispose (); | |
2288 return false; | |
2289 } | |
2290 } | |
2291 } | |
2292 gc.dispose (); | |
2293 if (firstColumn.width () < newWidth) { | |
2294 NSOutlineView outlineView = (NSOutlineView)view; | |
2295 int /*long*/ oldResize = outlineView.columnAutoresizingStyle (); | |
2296 outlineView.setColumnAutoresizingStyle (OS.NSTableViewNoColumnAutoresizing); | |
2297 firstColumn.setWidth (newWidth); | |
2298 outlineView.setColumnAutoresizingStyle (oldResize); | |
2299 return true; | |
2300 } | |
1931 return false; | 2301 return false; |
1932 } | |
1933 | |
1934 bool setScrollWidth (bool set) { | |
1935 // return setScrollWidth(set, childIds, true); | |
1936 return false; | |
1937 } | |
1938 | |
1939 bool setScrollWidth (bool set, int[] childIds, bool recurse) { | |
1940 // if (ignoreRedraw || drawCount !is 0) return false; | |
1941 // if (columnCount !is 0 || childIds is null) return false; | |
1942 // GC gc = new GC (this); | |
1943 // int newWidth = calculateWidth (childIds, gc, recurse, 0, 0); | |
1944 // gc.dispose (); | |
1945 // newWidth += getInsetWidth (column_id, false); | |
1946 // if (!set) { | |
1947 // short [] width = new short [1]; | |
1948 // OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width); | |
1949 // if (width [0] >= newWidth) return false; | |
1950 // } | |
1951 // OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, cast(short) newWidth); | |
1952 return true; | |
1953 } | 2302 } |
1954 | 2303 |
1955 /** | 2304 /** |
1956 * Sets the receiver's selection to the given item. | 2305 * Sets the receiver's selection to the given item. |
1957 * The current selection is cleared before the new item is selected. | 2306 * The current selection is cleared before the new item is selected. |
2002 */ | 2351 */ |
2003 public void setSelection (TreeItem [] items) { | 2352 public void setSelection (TreeItem [] items) { |
2004 checkWidget (); | 2353 checkWidget (); |
2005 if (items is null) error (DWT.ERROR_NULL_ARGUMENT); | 2354 if (items is null) error (DWT.ERROR_NULL_ARGUMENT); |
2006 deselectAll (); | 2355 deselectAll (); |
2007 // int length = items.length; | 2356 int length = items.length; |
2008 // if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return; | 2357 if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return; |
2009 // int count = 0; | 2358 NSOutlineView outlineView = (NSOutlineView) view; |
2010 // int[] ids = new int [length]; | 2359 NSMutableIndexSet rows = (NSMutableIndexSet) new NSMutableIndexSet ().alloc ().init (); |
2011 // for (int i=0; i<length; i++) { | 2360 rows.autorelease (); |
2012 // if (items [i] !is null) { | 2361 for (int i=0; i<length; i++) { |
2013 // if (items [i].isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | 2362 if (items [i] !is null) { |
2014 // ids [count++] = items [i].id; | 2363 if (items [i].isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); |
2015 // showItem (items [i], false); | 2364 TreeItem item = items [i]; |
2016 // } | 2365 showItem (items [i], false); |
2017 // } | 2366 rows.addIndex (outlineView.rowForItem (item.handle)); |
2018 // ignoreSelect = true; | 2367 } |
2019 // /* | 2368 } |
2020 // * Bug in the Macintosh. When the DataBroswer selection flags includes | 2369 ignoreSelect = true; |
2021 // * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne, | 2370 outlineView.selectRowIndexes (rows, false); |
2022 // * two items are selected when SetDataBrowserSelectedItems() is called | 2371 ignoreSelect = false; |
2023 // * with kDataBrowserItemsAssign to assign a new seletion despite the fact | 2372 if (items.length > 0) showItem(items[0], true); |
2024 // * that kDataBrowserSelectOnlyOne was specified. The fix is to save and | |
2025 // * restore kDataBrowserNeverEmptySelectionSet around each call to | |
2026 // * SetDataBrowserSelectedItems(). | |
2027 // */ | |
2028 // int [] selectionFlags = null; | |
2029 // if ((style & DWT.SINGLE) !is 0) { | |
2030 // selectionFlags = new int [1]; | |
2031 // OS.GetDataBrowserSelectionFlags (handle, selectionFlags); | |
2032 // OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet); | |
2033 // } | |
2034 // OS.SetDataBrowserSelectedItems (handle, count, ids, OS.kDataBrowserItemsAssign); | |
2035 // if ((style & DWT.SINGLE) !is 0) { | |
2036 // OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]); | |
2037 // } | |
2038 // ignoreSelect = false; | |
2039 // if (length > 0) { | |
2040 // int index = -1; | |
2041 // for (int i=0; i<items.length; i++) { | |
2042 // if (items [i] !is null) { | |
2043 // index = i; | |
2044 // break; | |
2045 // } | |
2046 // } | |
2047 // if (index !is -1) showItem (items [index], true); | |
2048 // } | |
2049 } | 2373 } |
2050 | 2374 |
2051 /** | 2375 /** |
2052 * Sets the column used by the sort indicator for the receiver. A null | 2376 * Sets the column used by the sort indicator for the receiver. A null |
2053 * value will clear the sort indicator. The current sort column is cleared | 2377 * value will clear the sort indicator. The current sort column is cleared |
2067 */ | 2391 */ |
2068 public void setSortColumn (TreeColumn column) { | 2392 public void setSortColumn (TreeColumn column) { |
2069 checkWidget (); | 2393 checkWidget (); |
2070 if (column !is null && column.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | 2394 if (column !is null && column.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); |
2071 if (column is sortColumn) return; | 2395 if (column is sortColumn) return; |
2072 // if (column is null) { | 2396 TreeColumn oldSortColumn = sortColumn; |
2073 // if (sortColumn !is null && !sortColumn.isDisposed () && sortDirection !is DWT.NONE) { | 2397 sortColumn = column; |
2074 // OS.SetDataBrowserSortOrder (handle, cast(short) OS.kDataBrowserOrderIncreasing); | 2398 if (sortDirection is DWT.NONE) return; |
2075 // sortColumn = null; | 2399 NSTableHeaderView headerView = ((NSOutlineView)view).headerView (); |
2076 // OS.SetDataBrowserSortProperty (handle, 0); | 2400 if (headerView is null) return; |
2077 // } | 2401 if (oldSortColumn !is null) { |
2078 // } | 2402 int /*long*/ index = ((NSOutlineView)view).columnWithIdentifier (oldSortColumn.nsColumn); |
2079 // sortColumn = column; | 2403 NSRect rect = headerView.headerRectOfColumn (index); |
2080 // if (sortColumn !is null && !sortColumn.isDisposed () && sortDirection !is DWT.NONE) { | 2404 headerView.setNeedsDisplayInRect (rect); |
2081 // OS.SetDataBrowserSortProperty (handle, sortColumn.id); | 2405 } |
2082 // int order = sortDirection is DWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing; | 2406 if (sortColumn !is null) { |
2083 // OS.SetDataBrowserSortOrder (handle, cast(short) order); | 2407 NSInteger index = (cast(NSOutlineView)view).columnWithIdentifier (sortColumn.nsColumn); |
2084 // } | 2408 NSRect rect = headerView.headerRectOfColumn (index); |
2409 headerView.setNeedsDisplayInRect (rect); | |
2410 } | |
2085 } | 2411 } |
2086 | 2412 |
2087 /** | 2413 /** |
2088 * Sets the direction of the sort indicator for the receiver. The value | 2414 * Sets the direction of the sort indicator for the receiver. The value |
2089 * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>. | 2415 * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>. |
2098 * @since 3.2 | 2424 * @since 3.2 |
2099 */ | 2425 */ |
2100 public void setSortDirection (int direction) { | 2426 public void setSortDirection (int direction) { |
2101 checkWidget (); | 2427 checkWidget (); |
2102 if (direction !is DWT.UP && direction !is DWT.DOWN && direction !is DWT.NONE) return; | 2428 if (direction !is DWT.UP && direction !is DWT.DOWN && direction !is DWT.NONE) return; |
2103 // if (direction is sortDirection) return; | 2429 if (direction is sortDirection) return; |
2104 // sortDirection = direction; | 2430 sortDirection = direction; |
2105 // if (sortColumn !is null && !sortColumn.isDisposed ()) { | 2431 if (sortColumn is null) return; |
2106 // if (sortDirection is DWT.NONE) { | 2432 NSTableHeaderView headerView = ((NSOutlineView)view).headerView (); |
2107 // OS.SetDataBrowserSortOrder (handle, cast(short) OS.kDataBrowserOrderIncreasing); | 2433 if (headerView is null) return; |
2108 // TreeColumn column = sortColumn; | 2434 int /*long*/ index = ((NSOutlineView)view).columnWithIdentifier (sortColumn.nsColumn); |
2109 // sortColumn = null; | 2435 NSRect rect = headerView.headerRectOfColumn (index); |
2110 // OS.SetDataBrowserSortProperty (handle, 0); | 2436 headerView.setNeedsDisplayInRect (rect); |
2111 // sortColumn = column; | |
2112 // } else { | |
2113 // OS.SetDataBrowserSortProperty (handle, 0); | |
2114 // OS.SetDataBrowserSortProperty (handle, sortColumn.id); | |
2115 // int order = sortDirection is DWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing; | |
2116 // OS.SetDataBrowserSortOrder (handle, cast(short) order); | |
2117 // } | |
2118 // } | |
2119 } | 2437 } |
2120 | 2438 |
2121 /** | 2439 /** |
2122 * Sets the item which is currently at the top of the receiver. | 2440 * Sets the item which is currently at the top of the receiver. |
2123 * This item can change when items are expanded, collapsed, scrolled | 2441 * This item can change when items are expanded, collapsed, scrolled |
2140 */ | 2458 */ |
2141 public void setTopItem (TreeItem item) { | 2459 public void setTopItem (TreeItem item) { |
2142 checkWidget(); | 2460 checkWidget(); |
2143 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | 2461 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); |
2144 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | 2462 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); |
2145 // showItem (item, false); | 2463 showItem (item, false); |
2146 // int columnId = (columnCount is 0) ? column_id : columns [0].id; | 2464 NSOutlineView outlineView = (NSOutlineView) view; |
2147 // OS.RevealDataBrowserItem (handle, item.id, columnId, cast(byte) OS.kDataBrowserRevealWithoutSelecting); | 2465 //FIXME |
2148 // Rect rect = new Rect (); | 2466 ((NSOutlineView) view).scrollRowToVisible (outlineView.rowForItem (item.handle)); |
2149 // if (OS.GetDataBrowserItemPartBounds (handle, item.id, column_id, OS.kDataBrowserPropertyEnclosingPart, rect) is OS.noErr) { | |
2150 // int border = getBorder (); | |
2151 // int [] top = new int [1], left = new int [1]; | |
2152 // OS.GetDataBrowserScrollPosition (handle, top, left); | |
2153 // OS.SetDataBrowserScrollPosition (handle, Math.max (0, top [0] + rect.top - border - getHeaderHeight ()), left [0]); | |
2154 // } | |
2155 } | 2467 } |
2156 | 2468 |
2157 /** | 2469 /** |
2158 * Shows the column. If the column is already showing in the receiver, | 2470 * Shows the column. If the column is already showing in the receiver, |
2159 * this method simply returns. Otherwise, the columns are scrolled until | 2471 * this method simply returns. Otherwise, the columns are scrolled until |
2173 * @since 3.1 | 2485 * @since 3.1 |
2174 */ | 2486 */ |
2175 public void showColumn (TreeColumn column) { | 2487 public void showColumn (TreeColumn column) { |
2176 checkWidget (); | 2488 checkWidget (); |
2177 if (column is null) error (DWT.ERROR_NULL_ARGUMENT); | 2489 if (column is null) error (DWT.ERROR_NULL_ARGUMENT); |
2178 if (column.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT); | 2490 if (column.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT); |
2179 if (column.parent !is this) return; | 2491 if (column.parent !is this) return; |
2180 int index = indexOf (column); | 2492 if (columnCount <= 1) return; |
2181 if (columnCount <= 1 || !(0 <= index && index < columnCount)) return; | 2493 int index = (int)/*64*/((NSOutlineView)view).columnWithIdentifier (column.nsColumn); |
2182 (cast(NSTableView)view).scrollColumnToVisible(index + ((style & DWT.CHECK) !is 0 ? 1 : 0)); | 2494 if (!(0 <= index && index < columnCount + ((style & DWT.CHECK) !is 0 ? 1 : 0))) return; |
2495 ((NSOutlineView)view).scrollColumnToVisible (index); | |
2183 } | 2496 } |
2184 | 2497 |
2185 /** | 2498 /** |
2186 * Shows the item. If the item is already showing in the receiver, | 2499 * Shows the item. If the item is already showing in the receiver, |
2187 * this method simply returns. Otherwise, the items are scrolled | 2500 * this method simply returns. Otherwise, the items are scrolled |
2206 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | 2519 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); |
2207 showItem (item, true); | 2520 showItem (item, true); |
2208 } | 2521 } |
2209 | 2522 |
2210 void showItem (TreeItem item, bool scroll) { | 2523 void showItem (TreeItem item, bool scroll) { |
2211 int count = 0; | 2524 TreeItem parentItem = item.parentItem; |
2212 // TreeItem parentItem = item.parentItem; | 2525 if (parentItem !is null && !parentItem.expanded) { |
2213 // while (parentItem !is null && !parentItem._getExpanded ()) { | 2526 showItem (parentItem, false); |
2214 // count++; | 2527 parentItem.setExpanded (true); |
2215 // parentItem = parentItem.parentItem; | 2528 } |
2216 // } | 2529 if (scroll) { |
2217 // int index = 0; | 2530 NSOutlineView outlineView = (NSOutlineView) view; |
2218 // parentItem = item.parentItem; | 2531 outlineView.scrollRowToVisible (outlineView.rowForItem (item.handle)); |
2219 // TreeItem [] path = new TreeItem [count]; | 2532 } |
2220 // while (parentItem !is null && !parentItem._getExpanded ()) { | |
2221 // path [index++] = parentItem; | |
2222 // parentItem = parentItem.parentItem; | |
2223 // } | |
2224 // for (int i=path.length-1; i>=0; --i) { | |
2225 // path [i].setExpanded (true); | |
2226 // } | |
2227 // if (scroll) { | |
2228 // /* | |
2229 // * Bug in the Macintosh. When there is not room to show a | |
2230 // * single item in the data browser, RevealDataBrowserItem() | |
2231 // * scrolls the item such that it is above the top of the data | |
2232 // * browser. The fix is to remember the index and scroll when | |
2233 // * the data browser is resized. | |
2234 // * | |
2235 // * Bug in the Macintosh. When items are added to the data | |
2236 // * browser after is has been hidden, RevealDataBrowserItem() | |
2237 // * when called before the controls behind the data browser | |
2238 // * are repainted causes a redraw. This redraw happens right | |
2239 // * away causing pixel corruption. The fix is to remember the | |
2240 // * index and scroll when the data browser is shown. | |
2241 // */ | |
2242 // Rectangle rect = getClientArea (); | |
2243 // if (rect.height < getItemHeight () || !OS.IsControlVisible (handle)) { | |
2244 // showItem = item; | |
2245 // return; | |
2246 // } | |
2247 // showItem = null; | |
2248 // Rectangle itemRect = item.getBounds (); | |
2249 // if (!itemRect.isEmpty()) { | |
2250 // if (rect.contains (itemRect.x, itemRect.y) | |
2251 // && rect.contains (itemRect.x, itemRect.y + itemRect.height)) return; | |
2252 // } | |
2253 // int [] top = new int [1], left = new int [1]; | |
2254 // OS.GetDataBrowserScrollPosition (handle, top, left); | |
2255 // int columnId = (columnCount is 0) ? column_id : columns [0].id; | |
2256 // int options = OS.kDataBrowserRevealWithoutSelecting; | |
2257 // /* | |
2258 // * This code is intentionally commented, since kDataBrowserRevealAndCenterInView | |
2259 // * does not scroll the item to the center always (it seems to scroll to the | |
2260 // * end in some cases). | |
2261 // */ | |
2262 // //options |= OS.kDataBrowserRevealAndCenterInView; | |
2263 // OS.RevealDataBrowserItem (handle, item.id, columnId, cast(byte) options); | |
2264 // int [] newTop = new int [1], newLeft = new int [1]; | |
2265 // if (columnCount is 0) { | |
2266 // bool fixScroll = false; | |
2267 // Rect content = new Rect (); | |
2268 // if (OS.GetDataBrowserItemPartBounds (handle, item.id, columnId, OS.kDataBrowserPropertyContentPart, content) is OS.noErr) { | |
2269 // fixScroll = content.left < rect.x || content.left >= rect.x + rect.width; | |
2270 // if (!fixScroll) { | |
2271 // GC gc = new GC (this); | |
2272 // int contentWidth = calculateWidth (new int[]{item.id}, gc, false, 0, 0); | |
2273 // gc.dispose (); | |
2274 // fixScroll = content.left + contentWidth > rect.x + rect.width; | |
2275 // } | |
2276 // } | |
2277 // if (fixScroll) { | |
2278 // int leftScroll = getLeftDisclosureInset (columnId); | |
2279 // int levelIndent = DISCLOSURE_COLUMN_LEVEL_INDENT; | |
2280 // if (OS.VERSION >= 0x1040) { | |
2281 // float [] metric = new float [1]; | |
2282 // OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricDisclosureColumnPerDepthGap, null, metric); | |
2283 // levelIndent = cast(int) metric [0]; | |
2284 // } | |
2285 // TreeItem temp = item; | |
2286 // while (temp.parentItem !is null) { | |
2287 // leftScroll += levelIndent; | |
2288 // temp = temp.parentItem; | |
2289 // } | |
2290 // OS.GetDataBrowserScrollPosition (handle, newTop, newLeft); | |
2291 // OS.SetDataBrowserScrollPosition (handle, newTop [0], leftScroll); | |
2292 // } | |
2293 // } | |
2294 // | |
2295 // /* | |
2296 // * Bug in the Macintosh. For some reason, when the DataBrowser is scrolled | |
2297 // * by RevealDataBrowserItem(), the scrollbars are not redrawn. The fix is to | |
2298 // * force a redraw. | |
2299 // */ | |
2300 // OS.GetDataBrowserScrollPosition (handle, newTop, newLeft); | |
2301 // if (horizontalBar !is null && newLeft [0] !is left [0]) horizontalBar.redraw (); | |
2302 // if (verticalBar !is null && newTop [0] !is top [0]) verticalBar.redraw (); | |
2303 // } | |
2304 } | 2533 } |
2305 | 2534 |
2306 /** | 2535 /** |
2307 * Shows the selection. If the selection is already showing in the receiver, | 2536 * Shows the selection. If the selection is already showing in the receiver, |
2308 * this method simply returns. Otherwise, the items are scrolled until | 2537 * this method simply returns. Otherwise, the items are scrolled until |
2322 TreeItem [] selection = getSelection (); | 2551 TreeItem [] selection = getSelection (); |
2323 if (selection.length > 0) showItem (selection [0], true); | 2552 if (selection.length > 0) showItem (selection [0], true); |
2324 } | 2553 } |
2325 | 2554 |
2326 } | 2555 } |
2556 |