| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | #include "lc_global.h" |
|---|
| 5 | #include "leocad.h" |
|---|
| 6 | #include "ClrPopup.h" |
|---|
| 7 | #include "ClrPick.h" |
|---|
| 8 | #include "lc_colors.h" |
|---|
| 9 | |
|---|
| 10 | #ifdef _DEBUG |
|---|
| 11 | #define new DEBUG_NEW |
|---|
| 12 | #undef THIS_FILE |
|---|
| 13 | static char THIS_FILE[] = __FILE__; |
|---|
| 14 | #endif |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | CColorPicker::CColorPicker() |
|---|
| 37 | { |
|---|
| 38 | m_bActive = FALSE; |
|---|
| 39 | m_nColor = -1; |
|---|
| 40 | SetColorIndex(-1); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | CColorPicker::~CColorPicker() |
|---|
| 44 | { |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | IMPLEMENT_DYNCREATE(CColorPicker, CButton) |
|---|
| 48 | |
|---|
| 49 | BEGIN_MESSAGE_MAP(CColorPicker, CButton) |
|---|
| 50 | |
|---|
| 51 | ON_CONTROL_REFLECT_EX(BN_CLICKED, OnClicked) |
|---|
| 52 | ON_WM_CREATE() |
|---|
| 53 | |
|---|
| 54 | ON_MESSAGE(CPN_SELENDOK, OnSelEndOK) |
|---|
| 55 | ON_MESSAGE(CPN_SELENDCANCEL, OnSelEndCancel) |
|---|
| 56 | END_MESSAGE_MAP() |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | LONG CColorPicker::OnSelEndOK(UINT , LONG wParam) |
|---|
| 62 | { |
|---|
| 63 | m_bActive = FALSE; |
|---|
| 64 | SetColorIndex(wParam); |
|---|
| 65 | |
|---|
| 66 | CWnd *pParent = GetParent(); |
|---|
| 67 | if (pParent) |
|---|
| 68 | pParent->SendMessage(CPN_SELENDOK, wParam, (LPARAM)GetDlgCtrlID()); |
|---|
| 69 | |
|---|
| 70 | return TRUE; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | LONG CColorPicker::OnSelEndCancel(UINT , LONG wParam) |
|---|
| 74 | { |
|---|
| 75 | m_bActive = FALSE; |
|---|
| 76 | |
|---|
| 77 | CWnd *pParent = GetParent(); |
|---|
| 78 | if (pParent) |
|---|
| 79 | pParent->SendMessage(CPN_SELENDCANCEL, (WPARAM)wParam, (LPARAM)GetDlgCtrlID()); |
|---|
| 80 | |
|---|
| 81 | return TRUE; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | int CColorPicker::OnCreate(LPCREATESTRUCT lpCreateStruct) |
|---|
| 85 | { |
|---|
| 86 | if (CButton::OnCreate(lpCreateStruct) == -1) |
|---|
| 87 | return -1; |
|---|
| 88 | |
|---|
| 89 | SetWindowSize(); |
|---|
| 90 | return 0; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | BOOL CColorPicker::OnClicked() |
|---|
| 95 | { |
|---|
| 96 | m_bActive = TRUE; |
|---|
| 97 | CRect rect; |
|---|
| 98 | GetWindowRect(rect); |
|---|
| 99 | new CColorPopup(CPoint(rect.left, rect.bottom), m_nColor, this); |
|---|
| 100 | |
|---|
| 101 | return TRUE; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | void CColorPicker::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) |
|---|
| 105 | { |
|---|
| 106 | ASSERT(lpDrawItemStruct); |
|---|
| 107 | |
|---|
| 108 | CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); |
|---|
| 109 | CRect rect = lpDrawItemStruct->rcItem; |
|---|
| 110 | UINT state = lpDrawItemStruct->itemState; |
|---|
| 111 | DWORD dwStyle = GetStyle(); |
|---|
| 112 | CString m_strText; |
|---|
| 113 | |
|---|
| 114 | CSize Margins(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE)); |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | if (m_bActive) state |= ODS_SELECTED; |
|---|
| 118 | pDC->DrawFrameControl(&m_ArrowRect, DFC_SCROLL, DFCS_SCROLLDOWN | |
|---|
| 119 | ((state & ODS_SELECTED) ? DFCS_PUSHED : 0) | |
|---|
| 120 | ((state & ODS_DISABLED) ? DFCS_INACTIVE : 0)); |
|---|
| 121 | |
|---|
| 122 | pDC->DrawEdge(rect, EDGE_SUNKEN, BF_RECT); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | rect.DeflateRect(Margins.cx, Margins.cy); |
|---|
| 126 | rect.bottom +=1; |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | rect.right -= m_ArrowRect.Width()-1; |
|---|
| 130 | |
|---|
| 131 | CBrush brush(((state & ODS_DISABLED) || m_nColor == -1)? ::GetSysColor(COLOR_3DFACE) : LC_COLOR_RGB(m_nColor)); |
|---|
| 132 | CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); |
|---|
| 133 | pDC->SelectStockObject(NULL_PEN); |
|---|
| 134 | pDC->Rectangle(rect); |
|---|
| 135 | pDC->SelectObject(pOldBrush); |
|---|
| 136 | |
|---|
| 137 | if (LC_COLOR_TRANSLUCENT(m_nColor)) |
|---|
| 138 | { |
|---|
| 139 | for (int x = rect.left; x < rect.right; x++) |
|---|
| 140 | { |
|---|
| 141 | int y; |
|---|
| 142 | |
|---|
| 143 | for (y = rect.top; y < rect.bottom; y+=4) |
|---|
| 144 | { |
|---|
| 145 | if (y == rect.top) y += x%4; |
|---|
| 146 | pDC->SetPixel (x,y,RGB(255,255,255)); |
|---|
| 147 | } |
|---|
| 148 | for (y = rect.bottom; y > rect.top; y-=4) |
|---|
| 149 | { |
|---|
| 150 | if (y == rect.bottom) y-= x%4; |
|---|
| 151 | pDC->SetPixel (x,y,RGB(255,255,255)); |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | if (state & ODS_FOCUS) |
|---|
| 158 | { |
|---|
| 159 | rect.DeflateRect(1,1); |
|---|
| 160 | pDC->DrawFocusRect(rect); |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | void CColorPicker::PreSubclassWindow() |
|---|
| 168 | { |
|---|
| 169 | ModifyStyle(0, BS_OWNERDRAW); |
|---|
| 170 | CButton::PreSubclassWindow(); |
|---|
| 171 | SetWindowSize(); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | int CColorPicker::GetColorIndex() |
|---|
| 178 | { |
|---|
| 179 | return m_nColor; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | void CColorPicker::SetColorIndex(int nColor) |
|---|
| 183 | { |
|---|
| 184 | if (m_nColor != nColor) |
|---|
| 185 | { |
|---|
| 186 | m_nColor = nColor; |
|---|
| 187 | if (IsWindow(m_hWnd)) |
|---|
| 188 | RedrawWindow(); |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | void CColorPicker::SetWindowSize() |
|---|
| 196 | { |
|---|
| 197 | |
|---|
| 198 | CSize MarginSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE)); |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | int nArrowWidth = max(::GetSystemMetrics(SM_CXHTHUMB), 5*MarginSize.cx); |
|---|
| 202 | int nArrowHeight = max(::GetSystemMetrics(SM_CYVTHUMB), 5*MarginSize.cy); |
|---|
| 203 | CSize ArrowSize(max(nArrowWidth, nArrowHeight), max(nArrowWidth, nArrowHeight)); |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | CRect rect; |
|---|
| 207 | GetWindowRect(rect); |
|---|
| 208 | |
|---|
| 209 | CWnd* pParent = GetParent(); |
|---|
| 210 | if (pParent) |
|---|
| 211 | pParent->ScreenToClient(rect); |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | int nWidth = max(rect.Width(), 2*ArrowSize.cx + 2*MarginSize.cx); |
|---|
| 215 | int nHeight = max(rect.Height(), ArrowSize.cy + 2*MarginSize.cy); |
|---|
| 216 | MoveWindow(rect.left, rect.top, nWidth, nHeight, TRUE); |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | GetWindowRect(rect); |
|---|
| 220 | ScreenToClient(rect); |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | m_ArrowRect.SetRect(rect.right - ArrowSize.cx - MarginSize.cx, |
|---|
| 224 | rect.top + MarginSize.cy, rect.right - MarginSize.cx, |
|---|
| 225 | rect.bottom - MarginSize.cy); |
|---|
| 226 | } |
|---|