comparison dwt/widgets/TableColumn.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
64 */ 64 */
65 public class TableColumn : Item { 65 public class TableColumn : Item {
66 Table parent; 66 Table parent;
67 NSTableColumn nsColumn; 67 NSTableColumn nsColumn;
68 String toolTipText, displayText; 68 String toolTipText, displayText;
69 69
70 static const int MARGIN = 2; 70 static const int MARGIN = 2;
71 71
72 /** 72 /**
73 * Constructs a new instance of this class given its parent 73 * Constructs a new instance of this class given its parent
74 * (which must be a <code>Table</code>) and a style value 74 * (which must be a <code>Table</code>) and a style value
75 * describing its behavior and appearance. The item is added 75 * describing its behavior and appearance. The item is added
76 * to the end of the items maintained by its parent. 76 * to the end of the items maintained by its parent.
228 } 228 }
229 229
230 void drawInteriorWithFrame_inView (objc.id id, objc.SEL sel, objc.id cellFrame, objc.id view) { 230 void drawInteriorWithFrame_inView (objc.id id, objc.SEL sel, objc.id cellFrame, objc.id view) {
231 NSRect cellRect = NSRect (); 231 NSRect cellRect = NSRect ();
232 OS.memmove (&cellRect, cellFrame, NSRect.sizeof); 232 OS.memmove (&cellRect, cellFrame, NSRect.sizeof);
233 233
234 /* 234 /*
235 * Feature in Cocoa. When the last column in a table does not reach the 235 * Feature in Cocoa. When the last column in a table does not reach the
236 * rightmost edge of the table view, the cell that draws the rightmost- 236 * rightmost edge of the table view, the cell that draws the rightmost-
237 * column's header is also invoked to draw the header space between its 237 * column's header is also invoked to draw the header space between its
238 * right edge and the table's right edge. If this case is detected then 238 * right edge and the table's right edge. If this case is detected then
240 */ 240 */
241 NSTableView tableView = cast(NSTableView)parent.view; 241 NSTableView tableView = cast(NSTableView)parent.view;
242 NSInteger columnIndex = tableView.columnWithIdentifier (nsColumn); 242 NSInteger columnIndex = tableView.columnWithIdentifier (nsColumn);
243 NSRect headerRect = parent.headerView.headerRectOfColumn (columnIndex); 243 NSRect headerRect = parent.headerView.headerRectOfColumn (columnIndex);
244 if (headerRect.x !is cellRect.x || headerRect.width !is cellRect.width) return; 244 if (headerRect.x !is cellRect.x || headerRect.width !is cellRect.width) return;
245 245
246 NSGraphicsContext context = NSGraphicsContext.currentContext (); 246 NSGraphicsContext context = NSGraphicsContext.currentContext ();
247 context.saveGraphicsState (); 247 context.saveGraphicsState ();
248 248
249 int contentWidth = 0; 249 int contentWidth = 0;
250 NSSize stringSize, imageSize; 250 NSSize stringSize, imageSize;
251 NSAttributedString attrString = null; 251 NSAttributedString attrString = null;
252 NSTableHeaderCell headerCell = nsColumn.headerCell (); 252 NSTableHeaderCell headerCell = nsColumn.headerCell ();
253 if (displayText !is null) { 253 if (displayText !is null) {
265 } 265 }
266 if (image !is null) { 266 if (image !is null) {
267 imageSize = image.handle.size (); 267 imageSize = image.handle.size ();
268 contentWidth += Math.ceil (imageSize.width); 268 contentWidth += Math.ceil (imageSize.width);
269 } 269 }
270 270
271 if (parent.sortColumn is this && parent.sortDirection !is DWT.NONE) { 271 if (parent.sortColumn is this && parent.sortDirection !is DWT.NONE) {
272 bool ascending = parent.sortDirection is DWT.UP; 272 bool ascending = parent.sortDirection is DWT.UP;
273 headerCell.drawSortIndicatorWithFrame (cellRect, new NSView(view), ascending, 0); 273 headerCell.drawSortIndicatorWithFrame (cellRect, new NSView(view), ascending, 0);
274 /* remove the arrow's space from the available drawing width */ 274 /* remove the arrow's space from the available drawing width */
275 NSRect sortRect = headerCell.sortIndicatorRectForBounds (cellRect); 275 NSRect sortRect = headerCell.sortIndicatorRectForBounds (cellRect);
276 cellRect.width = Math.max (0, sortRect.x - cellRect.x); 276 cellRect.width = Math.max (0, sortRect.x - cellRect.x);
277 } 277 }
278 278
279 int drawX = 0; 279 int drawX = 0;
280 if ((style & DWT.CENTER) !is 0) { 280 if ((style & DWT.CENTER) !is 0) {
281 drawX = cast(int)(cellRect.x + Math.max (MARGIN, ((cellRect.width - contentWidth) / 2))); 281 drawX = cast(int)(cellRect.x + Math.max (MARGIN, ((cellRect.width - contentWidth) / 2)));
282 } else if ((style & DWT.RIGHT) !is 0) { 282 } else if ((style & DWT.RIGHT) !is 0) {
283 drawX = cast(int)(cellRect.x + Math.max (MARGIN, cellRect.width - contentWidth - MARGIN)); 283 drawX = cast(int)(cellRect.x + Math.max (MARGIN, cellRect.width - contentWidth - MARGIN));
284 } else { 284 } else {
285 drawX = cast(int)cellRect.x + MARGIN; 285 drawX = cast(int)cellRect.x + MARGIN;
286 } 286 }
287 287
288 if (image !is null) { 288 if (image !is null) {
289 NSRect destRect = NSRect (); 289 NSRect destRect = NSRect ();
290 destRect.x = drawX; 290 destRect.x = drawX;
291 destRect.y = cellRect.y; 291 destRect.y = cellRect.y;
292 destRect.width = Math.min (imageSize.width, cellRect.width - 2 * MARGIN); 292 destRect.width = Math.min (imageSize.width, cellRect.width - 2 * MARGIN);
304 sourceRect.height = destRect.height; 304 sourceRect.height = destRect.height;
305 image.handle.drawInRect (destRect, sourceRect, OS.NSCompositeSourceOver, 1f); 305 image.handle.drawInRect (destRect, sourceRect, OS.NSCompositeSourceOver, 1f);
306 if (isFlipped) context.restoreGraphicsState (); 306 if (isFlipped) context.restoreGraphicsState ();
307 drawX += destRect.width; 307 drawX += destRect.width;
308 } 308 }
309 309
310 if (displayText !is null && displayText.length () > 0) { 310 if (displayText !is null && displayText.length () > 0) {
311 if (image !is null) drawX += MARGIN; /* space between image and text */ 311 if (image !is null) drawX += MARGIN; /* space between image and text */
312 NSRect destRect = NSRect (); 312 NSRect destRect = NSRect ();
313 destRect.x = drawX; 313 destRect.x = drawX;
314 destRect.y = cellRect.y; 314 destRect.y = cellRect.y;
315 destRect.width = Math.min (stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX); 315 destRect.width = Math.min (stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX);
316 destRect.height = Math.min (stringSize.height, cellRect.height); 316 destRect.height = Math.min (stringSize.height, cellRect.height);
317 attrString.drawInRect (destRect); 317 attrString.drawInRect (destRect);
318 attrString.release (); 318 attrString.release ();
319 } 319 }
320 320
321 context.restoreGraphicsState (); 321 context.restoreGraphicsState ();
322 } 322 }
323 323
324 /** 324 /**
325 * Returns a value which describes the position of the 325 * Returns a value which describes the position of the
380 * 380 *
381 * @since 3.1 381 * @since 3.1
382 */ 382 */
383 public bool getMoveable () { 383 public bool getMoveable () {
384 checkWidget (); 384 checkWidget ();
385 // int [] flags = new int [1]; 385 // int [] flags = new int [1];
386 // OS.GetDataBrowserPropertyFlags (parent.handle, id, flags); 386 // OS.GetDataBrowserPropertyFlags (parent.handle, id, flags);
387 // return (flags [0] & OS.kDataBrowserListViewMovableColumn) !is 0; 387 // return (flags [0] & OS.kDataBrowserListViewMovableColumn) !is 0;
388 return false; 388 return false;
389 } 389 }
390 390
391 /** 391 /**
392 * Gets the resizable attribute. A column that is 392 * Gets the resizable attribute. A column that is
449 * </ul> 449 * </ul>
450 * 450 *
451 */ 451 */
452 public void pack () { 452 public void pack () {
453 checkWidget (); 453 checkWidget ();
454 454
455 int width = 0; 455 int width = 0;
456 456
457 /* compute header width */ 457 /* compute header width */
458 if (displayText !is null) { 458 if (displayText !is null) {
459 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity (4); 459 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity (4);
460 NSTableHeaderCell headerCell = nsColumn.headerCell (); 460 NSTableHeaderCell headerCell = nsColumn.headerCell ();
461 dict.setObject (headerCell.font (), OS.NSFontAttributeName); 461 dict.setObject (headerCell.font (), OS.NSFontAttributeName);
477 NSSize cellSize = headerCell.cellSizeForBounds (rect); 477 NSSize cellSize = headerCell.cellSizeForBounds (rect);
478 rect.height = cellSize.height; 478 rect.height = cellSize.height;
479 NSRect sortRect = headerCell.sortIndicatorRectForBounds (rect); 479 NSRect sortRect = headerCell.sortIndicatorRectForBounds (rect);
480 width += Math.ceil (sortRect.width); 480 width += Math.ceil (sortRect.width);
481 } 481 }
482 482
483 /* compute item widths down column */ 483 /* compute item widths down column */
484 GC gc = new GC (parent); 484 GC gc = new GC (parent);
485 int index = parent.indexOf (this); 485 int index = parent.indexOf (this);
486 for (int i=0; i<parent.itemCount; i++) { 486 for (int i=0; i<parent.itemCount; i++) {
487 TableItem item = parent.items [i]; 487 TableItem item = parent.items [i];
635 checkWidget (); 635 checkWidget ();
636 // TODO how to make only some columns movable? And handle moveable is false. 636 // TODO how to make only some columns movable? And handle moveable is false.
637 if (moveable) { 637 if (moveable) {
638 (cast(NSTableView)parent.view).setAllowsColumnReordering (true); 638 (cast(NSTableView)parent.view).setAllowsColumnReordering (true);
639 } 639 }
640 // int [] flags = new int [1]; 640 // int [] flags = new int [1];
641 // OS.GetDataBrowserPropertyFlags (parent.handle, id, flags); 641 // OS.GetDataBrowserPropertyFlags (parent.handle, id, flags);
642 // if (moveable) { 642 // if (moveable) {
643 // flags [0] |= OS.kDataBrowserListViewMovableColumn; 643 // flags [0] |= OS.kDataBrowserListViewMovableColumn;
644 // } else { 644 // } else {
645 // flags [0] &= ~OS.kDataBrowserListViewMovableColumn; 645 // flags [0] &= ~OS.kDataBrowserListViewMovableColumn;
646 // } 646 // }
647 // OS.SetDataBrowserPropertyFlags (parent.handle, id, flags [0]); 647 // OS.SetDataBrowserPropertyFlags (parent.handle, id, flags [0]);
648 } 648 }
649 649
650 /** 650 /**
651 * Sets the resizable attribute. A column that is 651 * Sets the resizable attribute. A column that is
652 * resizable can be resized by the user dragging the 652 * resizable can be resized by the user dragging the