comparison dwt/widgets/TreeColumn.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children c749c13479ef
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
15 import dwt.DWT; 15 import dwt.DWT;
16 import dwt.DWTException; 16 import dwt.DWTException;
17 import dwt.events.ControlListener; 17 import dwt.events.ControlListener;
18 import dwt.events.SelectionEvent; 18 import dwt.events.SelectionEvent;
19 import dwt.events.SelectionListener; 19 import dwt.events.SelectionListener;
20 import dwt.graphics.GC;
21 import dwt.graphics.GCData;
22 import dwt.graphics.Image; 20 import dwt.graphics.Image;
23 import dwt.graphics.Rectangle; 21 import dwt.graphics.Rectangle;
24 import dwt.internal.win32.OS; 22 import dwt.internal.win32.OS;
25 23
26 import dwt.widgets.Item; 24 import dwt.widgets.Item;
105 * (that is, using the <code>int</code> "|" operator) two or more 103 * (that is, using the <code>int</code> "|" operator) two or more
106 * of those <code>DWT</code> style constants. The class description 104 * of those <code>DWT</code> style constants. The class description
107 * lists the style constants that are applicable to the class. 105 * lists the style constants that are applicable to the class.
108 * Style bits are also inherited from superclasses. 106 * Style bits are also inherited from superclasses.
109 * </p> 107 * </p>
110 * 108 * <p>
109 * Note that due to a restriction on some platforms, the first column
110 * is always left aligned.
111 * </p>
111 * @param parent a composite control which will be the parent of the new instance (cannot be null) 112 * @param parent a composite control which will be the parent of the new instance (cannot be null)
112 * @param style the style of control to construct 113 * @param style the style of control to construct
113 * @param index the zero-relative index to store the receiver in its parent 114 * @param index the zero-relative index to store the receiver in its parent
114 * 115 *
115 * @exception IllegalArgumentException <ul> 116 * @exception IllegalArgumentException <ul>
355 tvItem.hItem = cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0); 356 tvItem.hItem = cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
356 while (tvItem.hItem !is null) { 357 while (tvItem.hItem !is null) {
357 OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, cast(int) &tvItem); 358 OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, cast(int) &tvItem);
358 TreeItem item = tvItem.lParam !is -1 ? parent.items [tvItem.lParam] : null; 359 TreeItem item = tvItem.lParam !is -1 ? parent.items [tvItem.lParam] : null;
359 if (item !is null) { 360 if (item !is null) {
360 auto hFont = item.cellFont !is null ? item.cellFont [index] : cast(HFONT)-1; 361 int itemRight = 0;
361 if (hFont is cast(HFONT)-1) hFont = item.font;
362 if (hFont !is cast(HFONT)-1) hFont = OS.SelectObject (hDC, hFont);
363 RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC);
364 if (hFont !is cast(HFONT)-1) OS.SelectObject (hDC, hFont);
365 if (parent.hooks (DWT.MeasureItem)) { 362 if (parent.hooks (DWT.MeasureItem)) {
366 auto nSavedDC = OS.SaveDC (hDC); 363 Event event = parent.sendMeasureItemEvent (item, index, hDC);
367 GCData data = new GCData ();
368 data.device = display;
369 data.hFont = hFont;
370 GC gc = GC.win32_new (hDC, data);
371 Event event = new Event ();
372 event.item = item;
373 event.gc = gc;
374 event.index = index;
375 event.x = itemRect.left;
376 event.y = itemRect.top;
377 event.width = itemRect.right - itemRect.left;
378 event.height = itemRect.bottom - itemRect.top;
379 parent.sendEvent (DWT.MeasureItem, event);
380 event.gc = null;
381 gc.dispose ();
382 OS.RestoreDC (hDC, nSavedDC);
383 if (isDisposed () || parent.isDisposed ()) break; 364 if (isDisposed () || parent.isDisposed ()) break;
384 if (event.height > parent.getItemHeight ()) parent.setItemHeight (event.height); 365 itemRight = event.x + event.width;
385 //itemRect.left = event.x; 366 } else {
386 itemRect.right = event.x + event.width; 367 auto hFont = item.fontHandle (index);
368 if (hFont !is cast(HFONT)-1) hFont = OS.SelectObject (hDC, hFont);
369 RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC);
370 if (hFont !is cast(HFONT)-1) OS.SelectObject (hDC, hFont);
371 itemRight = itemRect.right;
387 } 372 }
388 columnWidth = Math.max (columnWidth, itemRect.right - headerRect.left); 373 columnWidth = Math.max (columnWidth, itemRight - headerRect.left);
389 } 374 }
390 tvItem.hItem = cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, tvItem.hItem); 375 tvItem.hItem = cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, tvItem.hItem);
391 } 376 }
392 RECT rect; 377 RECT rect;
393 int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX; 378 int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX;
488 473
489 /** 474 /**
490 * Controls how text and images will be displayed in the receiver. 475 * Controls how text and images will be displayed in the receiver.
491 * The argument should be one of <code>LEFT</code>, <code>RIGHT</code> 476 * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
492 * or <code>CENTER</code>. 477 * or <code>CENTER</code>.
493 * 478 * <p>
479 * Note that due to a restriction on some platforms, the first column
480 * is always left aligned.
481 * </p>
494 * @param alignment the new alignment 482 * @param alignment the new alignment
495 * 483 *
496 * @exception DWTException <ul> 484 * @exception DWTException <ul>
497 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 485 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
498 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 486 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
506 style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); 494 style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER);
507 style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER); 495 style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER);
508 auto hwndHeader = parent.hwndHeader; 496 auto hwndHeader = parent.hwndHeader;
509 if (hwndHeader is null) return; 497 if (hwndHeader is null) return;
510 HDITEM hdItem; 498 HDITEM hdItem;
511 hdItem.mask = OS.HDI_FORMAT | OS.HDI_IMAGE; 499 hdItem.mask = OS.HDI_FORMAT;
512 OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, &hdItem); 500 OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, &hdItem);
513 hdItem.fmt &= ~OS.HDF_JUSTIFYMASK; 501 hdItem.fmt &= ~OS.HDF_JUSTIFYMASK;
514 if ((style & DWT.LEFT) is DWT.LEFT) hdItem.fmt |= OS.HDF_LEFT; 502 if ((style & DWT.LEFT) is DWT.LEFT) hdItem.fmt |= OS.HDF_LEFT;
515 if ((style & DWT.CENTER) is DWT.CENTER) hdItem.fmt |= OS.HDF_CENTER; 503 if ((style & DWT.CENTER) is DWT.CENTER) hdItem.fmt |= OS.HDF_CENTER;
516 if ((style & DWT.RIGHT) is DWT.RIGHT) hdItem.fmt |= OS.HDF_RIGHT; 504 if ((style & DWT.RIGHT) is DWT.RIGHT) hdItem.fmt |= OS.HDF_RIGHT;
621 OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, &hdItem); 609 OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, &hdItem);
622 switch (direction) { 610 switch (direction) {
623 case DWT.UP: 611 case DWT.UP:
624 hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTDOWN); 612 hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTDOWN);
625 hdItem.fmt |= OS.HDF_SORTUP; 613 hdItem.fmt |= OS.HDF_SORTUP;
614 if (image is null) hdItem.mask &= ~OS.HDI_IMAGE;
626 break; 615 break;
627 case DWT.DOWN: 616 case DWT.DOWN:
628 hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTUP); 617 hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTUP);
629 hdItem.fmt |= OS.HDF_SORTDOWN; 618 hdItem.fmt |= OS.HDF_SORTDOWN;
619 if (image is null) hdItem.mask &= ~OS.HDI_IMAGE;
630 break; 620 break;
631 case DWT.NONE: 621 case DWT.NONE:
632 hdItem.fmt &= ~(OS.HDF_SORTUP | OS.HDF_SORTDOWN); 622 hdItem.fmt &= ~(OS.HDF_SORTUP | OS.HDF_SORTDOWN);
633 if (image !is null) { 623 if (image !is null) {
634 hdItem.fmt |= OS.HDF_IMAGE; 624 hdItem.fmt |= OS.HDF_IMAGE;
635 hdItem.iImage = parent.imageIndexHeader (image); 625 hdItem.iImage = parent.imageIndexHeader (image);
636 } else { 626 } else {
637 hdItem.fmt &= ~OS.HDF_IMAGE; 627 hdItem.fmt &= ~OS.HDF_IMAGE;
628 hdItem.mask &= ~OS.HDI_IMAGE;
638 } 629 }
639 break; 630 break;
640 default: 631 default:
641 } 632 }
642 OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, &hdItem); 633 OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, &hdItem);
679 * at the end of the text. The fix is to remove 670 * at the end of the text. The fix is to remove
680 * mnemonic characters and replace doubled mnemonics 671 * mnemonic characters and replace doubled mnemonics
681 * with spaces. 672 * with spaces.
682 */ 673 */
683 auto hHeap = OS.GetProcessHeap (); 674 auto hHeap = OS.GetProcessHeap ();
684 TCHAR[] buffer = StrToTCHARs (parent.getCodePage (), fixMnemonic (string), true); 675 TCHAR[] buffer = StrToTCHARs (parent.getCodePage (), fixMnemonic (string, true), true);
685 int byteCount = buffer.length * TCHAR.sizeof; 676 int byteCount = buffer.length * TCHAR.sizeof;
686 auto pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 677 auto pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
687 OS.MoveMemory (pszText, buffer.ptr, byteCount); 678 OS.MoveMemory (pszText, buffer.ptr, byteCount);
688 auto hwndHeader = parent.hwndHeader; 679 auto hwndHeader = parent.hwndHeader;
689 if (hwndHeader is null) return; 680 if (hwndHeader is null) return;