| | 582 | // Color property |
| | 583 | |
| | 584 | class CPropertyColorItem : public CPropertyReadOnlyItem |
| | 585 | { |
| | 586 | COLORREF m_color; |
| | 587 | public: |
| | 588 | CPropertyColorItem(LPCTSTR pstrName, LPARAM lParam) : CPropertyReadOnlyItem(pstrName, lParam) |
| | 589 | { |
| | 590 | } |
| | 591 | |
| | 592 | void DrawValue(PROPERTYDRAWINFO& di) |
| | 593 | { |
| | 594 | CPropertyReadOnlyItem::DrawValue(di); |
| | 595 | if (di.state & ODS_SELECTED) { |
| | 596 | CDCHandle dc(di.hDC); |
| | 597 | RECT rc = di.rcItem; |
| | 598 | rc.left = rc.right - 16; |
| | 599 | // Paint as ellipsis button |
| | 600 | dc.DrawFrameControl(&rc, DFC_BUTTON, DFCS_BUTTONPUSH); |
| | 601 | //dc.DrawFrameControl(&rc, DFC_BUTTON, (di.state & ODS_SELECTED) ? DFCS_BUTTONPUSH | DFCS_PUSHED : DFCS_BUTTONPUSH); |
| | 602 | dc.SetBkMode(TRANSPARENT); |
| | 603 | LPCTSTR pstrEllipsis = _T("..."); |
| | 604 | dc.DrawText(pstrEllipsis, ::lstrlen(pstrEllipsis), &rc, DT_CENTER | DT_EDITCONTROL | DT_SINGLELINE | DT_VCENTER); |
| | 605 | } |
| | 606 | } |
| | 607 | |
| | 608 | BOOL SetValue(const VARIANT& value) |
| | 609 | { |
| | 610 | ATLASSERT(V_VT(&value)==VT_UI4); |
| | 611 | m_val = value; |
| | 612 | m_color = m_val.uintVal; |
| | 613 | |
| | 614 | // create an icon with the new color |
| | 615 | CDC dc; |
| | 616 | dc.CreateCompatibleDC(0); |
| | 617 | CBitmap iconBitmap; |
| | 618 | SIZE sz = { ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON) }; |
| | 619 | |
| | 620 | iconBitmap.CreateBitmap(sz.cx, sz.cy, 1, 32, 0); |
| | 621 | RECT rcFull; |
| | 622 | RECT rc; |
| | 623 | SetRect(&rcFull, 0, 0, sz.cx, sz.cy ); |
| | 624 | SetRect(&rc, 0, 0, sz.cx, sz.cy-5 ); |
| | 625 | CBrush brush; |
| | 626 | CBrush whiteBrush; |
| | 627 | brush.CreateSolidBrush(m_color); |
| | 628 | whiteBrush.CreateSolidBrush(RGB(0xFF, 0xFF, 0xFF)); |
| | 629 | dc.SelectBitmap(iconBitmap); |
| | 630 | dc.FillRect(&rcFull, whiteBrush); |
| | 631 | dc.FillRect(&rc, brush); |
| | 632 | |
| | 633 | CBitmap iconMaskBitmap; |
| | 634 | iconMaskBitmap.CreateBitmap(sz.cx, sz.cy, 1, 32, 0); |
| | 635 | brush.DeleteObject(); |
| | 636 | brush.CreateSolidBrush(0); |
| | 637 | dc.SelectBitmap(iconMaskBitmap); |
| | 638 | dc.FillRect(&rcFull, whiteBrush); |
| | 639 | dc.FillRect(&rc, brush); |
| | 640 | |
| | 641 | ICONINFO ii; |
| | 642 | ii.fIcon = TRUE; |
| | 643 | ii.hbmColor = iconBitmap; |
| | 644 | ii.hbmMask = iconMaskBitmap; |
| | 645 | ii.xHotspot = 0; |
| | 646 | ii.yHotspot = 0; |
| | 647 | HICON hIcon = CreateIconIndirect(&ii); |
| | 648 | HICON hOldIcon = SetIcon(hIcon); |
| | 649 | if (hOldIcon != 0) |
| | 650 | DestroyIcon(hOldIcon); |
| | 651 | return TRUE; |
| | 652 | } |
| | 653 | BOOL SetValue(HWND /*hWnd*/) |
| | 654 | { |
| | 655 | // Do nothing... A value should be set on reacting to the button notification. |
| | 656 | // In other words: Use SetItemValue() in response to the PLN_BROWSE notification! |
| | 657 | return TRUE; |
| | 658 | } |
| | 659 | BOOL Activate(UINT action, LPARAM lParam) |
| | 660 | { |
| | 661 | RECT rc; |
| | 662 | GetClientRect(m_hWndOwner, &rc); |
| | 663 | WTL::CColorDialog clg(m_color, CC_FULLOPEN); |
| | 664 | switch( action ) { |
| | 665 | case PACT_CLICK: |
| | 666 | if (m_fEnabled) { |
| | 667 | int x = GET_X_LPARAM(lParam); |
| | 668 | if (x > rc.right - 20) { |
| | 669 | return Activate(PACT_BROWSE, 0); |
| | 670 | } |
| | 671 | } |
| | 672 | break; |
| | 673 | case PACT_BROWSE: |
| | 674 | if (IDOK == clg.DoModal(m_hWndOwner)) { |
| | 675 | CComVariant vCol = CComVariant(clg.m_cc.rgbResult); |
| | 676 | ::SendMessage(m_hWndOwner, WM_USER_PROP_CHANGEDPROPERTY, (WPARAM) (VARIANT*) &vCol, (LPARAM) this); |
| | 677 | } |
| | 678 | break; |
| | 679 | case PACT_DBLCLICK: |
| | 680 | // Let control owner know |
| | 681 | NMPROPERTYITEM nmh = { m_hWndOwner, ::GetDlgCtrlID(m_hWndOwner), PIN_BROWSE, this }; |
| | 682 | ::SendMessage(::GetParent(m_hWndOwner), WM_NOTIFY, nmh.hdr.idFrom, (LPARAM) &nmh); |
| | 683 | } |
| | 684 | return TRUE; |
| | 685 | } |
| | 686 | BOOL GetDisplayValue(LPTSTR pstr, UINT cchMax) const |
| | 687 | { |
| | 688 | #define RGBA_GETRED(rgb) (((rgb) >> 16) & 0xff) |
| | 689 | #define RGBA_GETGREEN(rgb) (((rgb) >> 8) & 0xff) |
| | 690 | #define RGBA_GETBLUE(rgb) ((rgb) & 0xff) |
| | 691 | ATLASSERT(V_VT(&m_val)==VT_UI4); |
| | 692 | lstrcpy(pstr, "#"); |
| | 693 | TCHAR szValue[64] = { 0 }; |
| | 694 | _itot(RGBA_GETRED(m_val.uintVal), szValue, 16); |
| | 695 | if (szValue[1] == '\0') lstrcat(pstr, "0"); |
| | 696 | lstrcat(pstr, szValue); |
| | 697 | |
| | 698 | _itot(RGBA_GETGREEN(m_val.uintVal), szValue, 16); |
| | 699 | if (szValue[1] == '\0') lstrcat(pstr, "0"); |
| | 700 | lstrcat(pstr, szValue); |
| | 701 | |
| | 702 | _itot(RGBA_GETBLUE(m_val.uintVal), szValue, 16); |
| | 703 | if (szValue[1] == '\0') lstrcat(pstr, "0"); |
| | 704 | lstrcat(pstr, szValue); |
| | 705 | return TRUE; |
| | 706 | } |
| | 707 | UINT GetDisplayValueLength() const |
| | 708 | { |
| | 709 | TCHAR szPath[MAX_PATH] = { 0 }; |
| | 710 | if( !GetDisplayValue(szPath, (sizeof(szPath) / sizeof(TCHAR)) - 1) ) return 0; |
| | 711 | return ::lstrlen(szPath); |
| | 712 | } |
| | 713 | }; |
| | 714 | |
| | 715 | |
| | 716 | ///////////////////////////////////////////////////////////////////////////// |