Mercurial > projects > dwt-mac
comparison dwt/widgets/TreeColumn.d @ 123:63a09873578e
Fixed compile errors
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 15 Jan 2009 23:08:54 +0100 |
parents | c7f7f4d7091a |
children |
comparison
equal
deleted
inserted
replaced
122:2e671fa40eec | 123:63a09873578e |
---|---|
66 */ | 66 */ |
67 public class TreeColumn : Item { | 67 public class TreeColumn : Item { |
68 NSTableColumn nsColumn; | 68 NSTableColumn nsColumn; |
69 Tree parent; | 69 Tree parent; |
70 String toolTipText, displayText; | 70 String toolTipText, displayText; |
71 | 71 |
72 static const int MARGIN = 2; | 72 static const int MARGIN = 2; |
73 | 73 |
74 /** | 74 /** |
75 * Constructs a new instance of this class given its parent | 75 * Constructs a new instance of this class given its parent |
76 * (which must be a <code>Tree</code>) and a style value | 76 * (which must be a <code>Tree</code>) and a style value |
77 * describing its behavior and appearance. The item is added | 77 * describing its behavior and appearance. The item is added |
78 * to the end of the items maintained by its parent. | 78 * to the end of the items maintained by its parent. |
230 } | 230 } |
231 | 231 |
232 void drawInteriorWithFrame_inView (objc.id id, objc.SEL sel, objc.id cellFrame, objc.id view) { | 232 void drawInteriorWithFrame_inView (objc.id id, objc.SEL sel, objc.id cellFrame, objc.id view) { |
233 NSRect cellRect = NSRect (); | 233 NSRect cellRect = NSRect (); |
234 OS.memmove (&cellRect, cellFrame, NSRect.sizeof); | 234 OS.memmove (&cellRect, cellFrame, NSRect.sizeof); |
235 | 235 |
236 /* | 236 /* |
237 * Feature in Cocoa. When the last column in a tree does not reach the | 237 * Feature in Cocoa. When the last column in a tree does not reach the |
238 * rightmost edge of the tree view, the cell that draws the rightmost- | 238 * rightmost edge of the tree view, the cell that draws the rightmost- |
239 * column's header is also invoked to draw the header space between its | 239 * column's header is also invoked to draw the header space between its |
240 * right edge and the tree's right edge. If this case is detected then | 240 * right edge and the tree's right edge. If this case is detected then |
242 */ | 242 */ |
243 NSOutlineView outlineView = cast(NSOutlineView)parent.view; | 243 NSOutlineView outlineView = cast(NSOutlineView)parent.view; |
244 NSInteger columnIndex = outlineView.columnWithIdentifier (nsColumn); | 244 NSInteger columnIndex = outlineView.columnWithIdentifier (nsColumn); |
245 NSRect headerRect = parent.headerView.headerRectOfColumn (columnIndex); | 245 NSRect headerRect = parent.headerView.headerRectOfColumn (columnIndex); |
246 if (headerRect.x !is cellRect.x || headerRect.width !is cellRect.width) return; | 246 if (headerRect.x !is cellRect.x || headerRect.width !is cellRect.width) return; |
247 | 247 |
248 NSGraphicsContext context = NSGraphicsContext.currentContext (); | 248 NSGraphicsContext context = NSGraphicsContext.currentContext (); |
249 context.saveGraphicsState (); | 249 context.saveGraphicsState (); |
250 | 250 |
251 int contentWidth = 0; | 251 int contentWidth = 0; |
252 NSSize stringSize, imageSize; | 252 NSSize stringSize, imageSize; |
253 NSAttributedString attrString = null; | 253 NSAttributedString attrString = null; |
254 NSTableHeaderCell headerCell = nsColumn.headerCell (); | 254 NSTableHeaderCell headerCell = nsColumn.headerCell (); |
255 if (displayText !is null) { | 255 if (displayText !is null) { |
267 } | 267 } |
268 if (image !is null) { | 268 if (image !is null) { |
269 imageSize = image.handle.size (); | 269 imageSize = image.handle.size (); |
270 contentWidth += Math.ceil (imageSize.width); | 270 contentWidth += Math.ceil (imageSize.width); |
271 } | 271 } |
272 | 272 |
273 if (parent.sortColumn is this && parent.sortDirection !is DWT.NONE) { | 273 if (parent.sortColumn is this && parent.sortDirection !is DWT.NONE) { |
274 bool ascending = parent.sortDirection is DWT.UP; | 274 bool ascending = parent.sortDirection is DWT.UP; |
275 headerCell.drawSortIndicatorWithFrame (cellRect, new NSView(view), ascending, 0); | 275 headerCell.drawSortIndicatorWithFrame (cellRect, new NSView(view), ascending, 0); |
276 /* remove the arrow's space from the available drawing width */ | 276 /* remove the arrow's space from the available drawing width */ |
277 NSRect sortRect = headerCell.sortIndicatorRectForBounds (cellRect); | 277 NSRect sortRect = headerCell.sortIndicatorRectForBounds (cellRect); |
278 cellRect.width = Math.max (0, sortRect.x - cellRect.x); | 278 cellRect.width = Math.max (0, sortRect.x - cellRect.x); |
279 } | 279 } |
280 | 280 |
281 int drawX = 0; | 281 int drawX = 0; |
282 if ((style & DWT.CENTER) !is 0) { | 282 if ((style & DWT.CENTER) !is 0) { |
283 drawX = cast(int)(cellRect.x + Math.max (MARGIN, ((cellRect.width - contentWidth) / 2))); | 283 drawX = cast(int)(cellRect.x + Math.max (MARGIN, ((cellRect.width - contentWidth) / 2))); |
284 } else if ((style & DWT.RIGHT) !is 0) { | 284 } else if ((style & DWT.RIGHT) !is 0) { |
285 drawX = cast(int)(cellRect.x + Math.max (MARGIN, cellRect.width - contentWidth - MARGIN)); | 285 drawX = cast(int)(cellRect.x + Math.max (MARGIN, cellRect.width - contentWidth - MARGIN)); |
286 } else { | 286 } else { |
287 drawX = cast(int)cellRect.x + MARGIN; | 287 drawX = cast(int)cellRect.x + MARGIN; |
288 } | 288 } |
289 | 289 |
290 if (image !is null) { | 290 if (image !is null) { |
291 NSRect destRect = NSRect (); | 291 NSRect destRect = NSRect (); |
292 destRect.x = drawX; | 292 destRect.x = drawX; |
293 destRect.y = cellRect.y; | 293 destRect.y = cellRect.y; |
294 destRect.width = Math.min (imageSize.width, cellRect.width - 2 * MARGIN); | 294 destRect.width = Math.min (imageSize.width, cellRect.width - 2 * MARGIN); |
306 sourceRect.height = destRect.height; | 306 sourceRect.height = destRect.height; |
307 image.handle.drawInRect (destRect, sourceRect, OS.NSCompositeSourceOver, 1f); | 307 image.handle.drawInRect (destRect, sourceRect, OS.NSCompositeSourceOver, 1f); |
308 if (isFlipped) context.restoreGraphicsState (); | 308 if (isFlipped) context.restoreGraphicsState (); |
309 drawX += destRect.width; | 309 drawX += destRect.width; |
310 } | 310 } |
311 | 311 |
312 if (displayText !is null && displayText.length () > 0) { | 312 if (displayText !is null && displayText.length () > 0) { |
313 if (image !is null) drawX += MARGIN; /* space between image and text */ | 313 if (image !is null) drawX += MARGIN; /* space between image and text */ |
314 NSRect destRect = NSRect (); | 314 NSRect destRect = NSRect (); |
315 destRect.x = drawX; | 315 destRect.x = drawX; |
316 destRect.y = cellRect.y; | 316 destRect.y = cellRect.y; |
317 destRect.width = Math.min (stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX); | 317 destRect.width = Math.min (stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX); |
318 destRect.height = Math.min (stringSize.height, cellRect.height); | 318 destRect.height = Math.min (stringSize.height, cellRect.height); |
319 attrString.drawInRect (destRect); | 319 attrString.drawInRect (destRect); |
320 attrString.release (); | 320 attrString.release (); |
321 } | 321 } |
322 | 322 |
323 context.restoreGraphicsState (); | 323 context.restoreGraphicsState (); |
324 } | 324 } |
325 | 325 |
326 /** | 326 /** |
327 * Returns a value which describes the position of the | 327 * Returns a value which describes the position of the |
382 * | 382 * |
383 * @since 3.2 | 383 * @since 3.2 |
384 */ | 384 */ |
385 public bool getMoveable () { | 385 public bool getMoveable () { |
386 checkWidget (); | 386 checkWidget (); |
387 // int [] flags = new int [1]; | 387 // int [] flags = new int [1]; |
388 // OS.GetDataBrowserPropertyFlags (parent.handle, id, flags); | 388 // OS.GetDataBrowserPropertyFlags (parent.handle, id, flags); |
389 // return (flags [0] & OS.kDataBrowserListViewMovableColumn) !is 0; | 389 // return (flags [0] & OS.kDataBrowserListViewMovableColumn) !is 0; |
390 return false; | 390 return false; |
391 } | 391 } |
392 | 392 |
393 /** | 393 /** |
394 * Gets the resizable attribute. A column that is | 394 * Gets the resizable attribute. A column that is |
451 * </ul> | 451 * </ul> |
452 * | 452 * |
453 */ | 453 */ |
454 public void pack () { | 454 public void pack () { |
455 checkWidget (); | 455 checkWidget (); |
456 | 456 |
457 int width = 0; | 457 int width = 0; |
458 | 458 |
459 /* compute header width */ | 459 /* compute header width */ |
460 if (displayText !is null) { | 460 if (displayText !is null) { |
461 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity (4); | 461 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity (4); |
462 NSTableHeaderCell headerCell = nsColumn.headerCell (); | 462 NSTableHeaderCell headerCell = nsColumn.headerCell (); |
463 dict.setObject (headerCell.font (), OS.NSFontAttributeName); | 463 dict.setObject (headerCell.font (), OS.NSFontAttributeName); |
479 NSSize cellSize = headerCell.cellSizeForBounds (rect); | 479 NSSize cellSize = headerCell.cellSizeForBounds (rect); |
480 rect.height = cellSize.height; | 480 rect.height = cellSize.height; |
481 NSRect sortRect = headerCell.sortIndicatorRectForBounds (rect); | 481 NSRect sortRect = headerCell.sortIndicatorRectForBounds (rect); |
482 width += Math.ceil (sortRect.width); | 482 width += Math.ceil (sortRect.width); |
483 } | 483 } |
484 | 484 |
485 /* compute item widths down column */ | 485 /* compute item widths down column */ |
486 GC gc = new GC (parent); | 486 GC gc = new GC (parent); |
487 int index = parent.indexOf (this); | 487 int index = parent.indexOf (this); |
488 for (int i=0; i<parent.itemCount; i++) { | 488 for (int i=0; i<parent.itemCount; i++) { |
489 TreeItem item = parent.items [i]; | 489 TreeItem item = parent.items [i]; |
637 checkWidget (); | 637 checkWidget (); |
638 // TODO how to make only some columns movable? And handle moveable is false. | 638 // TODO how to make only some columns movable? And handle moveable is false. |
639 if (moveable) { | 639 if (moveable) { |
640 (cast(NSOutlineView)parent.view).setAllowsColumnReordering (true); | 640 (cast(NSOutlineView)parent.view).setAllowsColumnReordering (true); |
641 } | 641 } |
642 // int [] flags = new int [1]; | 642 // int [] flags = new int [1]; |
643 // OS.GetDataBrowserPropertyFlags (parent.handle, id, flags); | 643 // OS.GetDataBrowserPropertyFlags (parent.handle, id, flags); |
644 // if (moveable) { | 644 // if (moveable) { |
645 // flags [0] |= OS.kDataBrowserListViewMovableColumn; | 645 // flags [0] |= OS.kDataBrowserListViewMovableColumn; |
646 // } else { | 646 // } else { |
647 // flags [0] &= ~OS.kDataBrowserListViewMovableColumn; | 647 // flags [0] &= ~OS.kDataBrowserListViewMovableColumn; |
648 // } | 648 // } |
649 // OS.SetDataBrowserPropertyFlags (parent.handle, id, flags [0]); | 649 // OS.SetDataBrowserPropertyFlags (parent.handle, id, flags [0]); |
650 } | 650 } |
651 | 651 |
652 /** | 652 /** |
653 * Sets the resizable attribute. A column that is | 653 * Sets the resizable attribute. A column that is |
654 * not resizable cannot be dragged by the user but | 654 * not resizable cannot be dragged by the user but |