comparison dwt/widgets/ExpandBar.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 fd9c62a2998e
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
283 bool drawFocus = false; 283 bool drawFocus = false;
284 if (handle is OS.GetFocus ()) { 284 if (handle is OS.GetFocus ()) {
285 int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); 285 int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
286 drawFocus = (uiState & OS.UISF_HIDEFOCUS) is 0; 286 drawFocus = (uiState & OS.UISF_HIDEFOCUS) is 0;
287 } 287 }
288 HFONT hCaptionFont, oldFont; 288 HFONT hCurrentFont, oldFont;
289 if (hTheme is null) { 289 if (hTheme is null) {
290 static if (!OS.IsWinCE ) { 290 if (hFont !is null) {
291 if (hFont is null) { 291 hCurrentFont = hFont;
292 } else {
293 if (!OS.IsWinCE) {
292 NONCLIENTMETRICS info; 294 NONCLIENTMETRICS info;
293 info.cbSize = NONCLIENTMETRICS.sizeof; 295 info.cbSize = NONCLIENTMETRICS.sizeof;
294 if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, &info, 0)) { 296 if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, &info, 0)) {
295 LOGFONT* logFont = &info.lfCaptionFont; 297 LOGFONT* logFont = &info.lfCaptionFont;
296 hCaptionFont = OS.CreateFontIndirect (logFont); 298 hCurrentFont = OS.CreateFontIndirect (logFont);
297 oldFont = OS.SelectObject (gc.handle, hCaptionFont);
298 } 299 }
299 } 300 }
301 }
302 if (hCurrentFont !is null) {
303 oldFont = OS.SelectObject (gc.handle, hCurrentFont);
304 }
305 if (foreground !is -1) {
306 OS.SetTextColor (gc.handle, foreground);
300 } 307 }
301 } 308 }
302 for (int i = 0; i < itemCount; i++) { 309 for (int i = 0; i < itemCount; i++) {
303 ExpandItem item = items[i]; 310 ExpandItem item = items[i];
304 item.drawItem (gc, hTheme, clipRect, item is focusItem && drawFocus); 311 item.drawItem (gc, hTheme, clipRect, item is focusItem && drawFocus);
305 } 312 }
306 if (hCaptionFont !is null) { 313 if (hCurrentFont !is null) {
307 OS.SelectObject (gc.handle, oldFont); 314 OS.SelectObject (gc.handle, oldFont);
308 OS.DeleteObject (hCaptionFont); 315 if (hCurrentFont !is hFont) OS.DeleteObject (hCurrentFont);
309 } 316 }
310 } 317 }
311 318
312 override Control findBackgroundControl () { 319 override Control findBackgroundControl () {
313 Control control = super.findBackgroundControl (); 320 Control control = super.findBackgroundControl ();
580 item.redraw (true); 587 item.redraw (true);
581 int index = indexOf (item); 588 int index = indexOf (item);
582 layoutItems (index + 1, true); 589 layoutItems (index + 1, true);
583 } 590 }
584 591
592 void showFocus (bool up) {
593 RECT rect;
594 OS.GetClientRect (handle, &rect);
595 int height = rect.bottom - rect.top;
596 int updateY = 0;
597 if (up) {
598 if (focusItem.y < 0) {
599 updateY = Math.min (yCurrentScroll, -focusItem.y);
600 }
601 } else {
602 int itemHeight = focusItem.y + getBandHeight ();
603 if (focusItem.expanded) {
604 if (height >= getBandHeight () + focusItem.height) {
605 itemHeight += focusItem.height;
606 }
607 }
608 if (itemHeight > height) {
609 updateY = height - itemHeight;
610 }
611 }
612 if (updateY !is 0) {
613 yCurrentScroll = Math.max (0, yCurrentScroll - updateY);
614 if ((style & DWT.V_SCROLL) !is 0) {
615 SCROLLINFO info;
616 info.cbSize = SCROLLINFO.sizeof;
617 info.fMask = OS.SIF_POS;
618 info.nPos = yCurrentScroll;
619 OS.SetScrollInfo (handle, OS.SB_VERT, &info, true);
620 }
621 OS.ScrollWindowEx (handle, 0, updateY, null, null, null, null, OS.SW_SCROLLCHILDREN | OS.SW_INVALIDATE);
622 for (int i = 0; i < itemCount; i++) {
623 items [i].y += updateY;
624 }
625 }
626 }
627
585 override String windowClass () { 628 override String windowClass () {
586 return display.windowClass(); 629 return display.windowClass;
587 } 630 }
588 631
589 override int windowProc () { 632 override int windowProc () {
590 return cast(int) display.windowProc; 633 return cast(int) display.windowProc;
591 } 634 }
608 int focusIndex = indexOf (focusItem); 651 int focusIndex = indexOf (focusItem);
609 if (focusIndex > 0) { 652 if (focusIndex > 0) {
610 focusItem.redraw (true); 653 focusItem.redraw (true);
611 focusItem = items [focusIndex - 1]; 654 focusItem = items [focusIndex - 1];
612 focusItem.redraw (true); 655 focusItem.redraw (true);
656 showFocus (true);
613 return LRESULT.ZERO; 657 return LRESULT.ZERO;
614 } 658 }
615 break; 659 break;
616 } 660 }
617 case OS.VK_DOWN: { 661 case OS.VK_DOWN: {
618 int focusIndex = indexOf (focusItem); 662 int focusIndex = indexOf (focusItem);
619 if (focusIndex < itemCount - 1) { 663 if (focusIndex < itemCount - 1) {
620 focusItem.redraw (true); 664 focusItem.redraw (true);
621 focusItem = items [focusIndex + 1]; 665 focusItem = items [focusIndex + 1];
622 focusItem.redraw (true); 666 focusItem.redraw (true);
667 showFocus (false);
623 return LRESULT.ZERO; 668 return LRESULT.ZERO;
624 } 669 }
625 break; 670 break;
626 } 671 }
627 default: 672 default:
628 } 673 }
629 return result; 674 return result;
630 } 675 }
631 676
632 override LRESULT WM_KILLFOCUS (int wParam, int lParam) { 677 override LRESULT WM_KILLFOCUS (int wParam, int lParam) {
633 trc(__LINE__);
634 LRESULT result = super.WM_KILLFOCUS (wParam, lParam); 678 LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
635 if (focusItem !is null) focusItem.redraw (true); 679 if (focusItem !is null) focusItem.redraw (true);
636 return result; 680 return result;
637 } 681 }
638 682
639 override LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { 683 override LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
640 //trc(__LINE__);
641 LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam); 684 LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
642 if (result is LRESULT.ZERO) return result; 685 if (result is LRESULT.ZERO) return result;
643 int x = cast(short) (lParam & 0xFFFF); 686 int x = OS.GET_X_LPARAM (lParam);
644 int y = cast(short) (lParam >> 16); 687 int y = OS.GET_Y_LPARAM (lParam);
645 for (int i = 0; i < itemCount; i++) { 688 for (int i = 0; i < itemCount; i++) {
646 ExpandItem item = items[i]; 689 ExpandItem item = items[i];
647 bool hover = item.isHover (x, y); 690 bool hover = item.isHover (x, y);
648 if (hover && focusItem !is item) { 691 if (hover && focusItem !is item) {
649 focusItem.redraw (true); 692 focusItem.redraw (true);
658 701
659 override LRESULT WM_LBUTTONUP (int wParam, int lParam) { 702 override LRESULT WM_LBUTTONUP (int wParam, int lParam) {
660 LRESULT result = super.WM_LBUTTONUP (wParam, lParam); 703 LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
661 if (result is LRESULT.ZERO) return result; 704 if (result is LRESULT.ZERO) return result;
662 if (focusItem is null) return result; 705 if (focusItem is null) return result;
663 int x = cast(short) (lParam & 0xFFFF); 706 int x = OS.GET_X_LPARAM (lParam);
664 int y = cast(short) (lParam >> 16); 707 int y = OS.GET_Y_LPARAM (lParam);
665 bool hover = focusItem.isHover (x, y); 708 bool hover = focusItem.isHover (x, y);
666 if (hover) { 709 if (hover) {
667 Event event = new Event (); 710 Event event = new Event ();
668 event.item = focusItem; 711 event.item = focusItem;
669 sendEvent (focusItem.expanded ? DWT.Collapse : DWT.Expand, event); 712 sendEvent (focusItem.expanded ? DWT.Collapse : DWT.Expand, event);
687 } 730 }
688 return result; 731 return result;
689 } 732 }
690 733
691 override LRESULT WM_MOUSEMOVE (int wParam, int lParam) { 734 override LRESULT WM_MOUSEMOVE (int wParam, int lParam) {
692 trc(__LINE__);
693 LRESULT result = super.WM_MOUSEMOVE (wParam, lParam); 735 LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
694 if (result is LRESULT.ZERO) return result; 736 if (result is LRESULT.ZERO) return result;
695 int x = cast(short) (lParam & 0xFFFF); 737 int x = OS.GET_X_LPARAM (lParam);
696 int y = cast(short) (lParam >> 16); 738 int y = OS.GET_Y_LPARAM (lParam);
697 for (int i = 0; i < itemCount; i++) { 739 for (int i = 0; i < itemCount; i++) {
698 ExpandItem item = items [i]; 740 ExpandItem item = items [i];
699 bool hover = item.isHover (x, y); 741 bool hover = item.isHover (x, y);
700 if (item.hover !is hover) { 742 if (item.hover !is hover) {
701 item.hover = hover; 743 item.hover = hover;
751 793
752 override LRESULT WM_SETCURSOR (int wParam, int lParam) { 794 override LRESULT WM_SETCURSOR (int wParam, int lParam) {
753 trc(__LINE__); 795 trc(__LINE__);
754 LRESULT result = super.WM_SETCURSOR (wParam, lParam); 796 LRESULT result = super.WM_SETCURSOR (wParam, lParam);
755 if (result !is null) return result; 797 if (result !is null) return result;
756 int hitTest = lParam & 0xFFFF; 798 int hitTest = cast(short) OS.LOWORD (lParam);
757 if (hitTest is OS.HTCLIENT) { 799 if (hitTest is OS.HTCLIENT) {
758 for (int i = 0; i < itemCount; i++) { 800 for (int i = 0; i < itemCount; i++) {
759 ExpandItem item = items [i]; 801 ExpandItem item = items [i];
760 if (item.hover) { 802 if (item.hover) {
761 auto hCursor = OS.LoadCursor (null, OS.IDC_HAND); 803 auto hCursor = OS.LoadCursor (null, OS.IDC_HAND);