Use color popoup for the colors in the Properties Pane.

This commit is contained in:
leo 2012-06-20 21:47:57 +00:00
parent a42fe600ca
commit 9bc700a8f4
5 changed files with 49 additions and 27 deletions

View file

@ -78,7 +78,7 @@ BOOL CColorPicker::OnClicked()
m_bActive = TRUE;
CRect rect;
GetWindowRect(rect);
new CColorPopup(CPoint(rect.left, rect.bottom), m_nColor, this);
new CColorPopup(CPoint(rect.left, rect.bottom), m_nColor, this, false);
return TRUE;
}

View file

@ -2,7 +2,7 @@
#include <math.h>
#include "ClrPick.h"
#include "ClrPopup.h"
#include "resource.h"
#include "propertiesgridctrl.h"
#include "lc_colors.h"
#ifdef _DEBUG
@ -23,12 +23,13 @@ CColorPopup::CColorPopup()
Initialise();
}
CColorPopup::CColorPopup(CPoint p, int nColor, CWnd* pParentWnd)
CColorPopup::CColorPopup(CPoint p, int nColor, CWnd* pParentWnd, bool IgnoreMouse)
{
Initialise();
m_nColor = m_nInitialColor = nColor;
m_pParent = pParentWnd;
m_IgnoreMouse = IgnoreMouse;
CColorPopup::Create(p, nColor, pParentWnd);
}
@ -43,6 +44,7 @@ void CColorPopup::Initialise()
m_nChosenColorSel = INVALID_COLOUR;
m_pParent = NULL;
m_nColor = m_nInitialColor = 0;
m_IgnoreMouse = false;
// Idiot check: Make sure the colour square is at least 5 x 5;
if (m_nBoxSize - 2 * m_nMargin - 2 < 5)
@ -86,7 +88,7 @@ CColorPopup::~CColorPopup()
BOOL CColorPopup::Create(CPoint p, int nColor, CWnd* pParentWnd)
{
ASSERT(pParentWnd && ::IsWindow(pParentWnd->GetSafeHwnd()));
ASSERT(pParentWnd->IsKindOf(RUNTIME_CLASS(CColorPicker)));
ASSERT(pParentWnd->IsKindOf(RUNTIME_CLASS(CColorPicker)) || pParentWnd->IsKindOf(RUNTIME_CLASS(CMFCPropertyGridCtrl)));
m_pParent = pParentWnd;
m_nColor = m_nInitialColor = nColor;
@ -279,6 +281,8 @@ void CColorPopup::OnMouseMove(UINT nFlags, CPoint point)
return;
}
m_IgnoreMouse = false;
// Has the row/col selection changed? If yes, then redraw old and new cells.
if (nNewSelection != m_nCurrentSel)
ChangeSelection(nNewSelection);
@ -291,6 +295,12 @@ void CColorPopup::OnLButtonUp(UINT nFlags, CPoint point)
{
CWnd::OnLButtonUp(nFlags, point);
if (m_IgnoreMouse)
{
m_IgnoreMouse = false;
return;
}
DWORD pos = GetMessagePos();
point = CPoint(LOWORD(pos), HIWORD(pos));
@ -462,8 +472,15 @@ void CColorPopup::EndSelection(int nMessage)
if (nMessage == CPN_SELENDCANCEL)
m_nColor = m_nInitialColor;
int ColorIndex = m_nCurrentSel >= 0 ? mCells[m_nCurrentSel].ColorIndex : 0;
m_pParent->SendMessage(nMessage, 0, (LPARAM)ColorIndex);
int ColorIndex = m_nColor >= 0 ? mCells[m_nColor].ColorIndex : 0;
if (m_pParent->IsKindOf(RUNTIME_CLASS(CMFCPropertyGridCtrl)))
{
CLeoCADMFCPropertyGridCtrl* Ctrl = (CLeoCADMFCPropertyGridCtrl*)m_pParent;
Ctrl->SetColor(ColorIndex);
}
else
m_pParent->SendMessage(nMessage, 0, (LPARAM)ColorIndex);
DestroyWindow();
}

View file

@ -23,7 +23,7 @@ class CColorPopup : public CWnd
// Construction
public:
CColorPopup();
CColorPopup(CPoint p, int nColor, CWnd* pParentWnd);
CColorPopup(CPoint p, int nColor, CWnd* pParentWnd, bool IgnoreMouse);
void Initialise();
// Attributes
@ -66,6 +66,7 @@ protected:
int m_nInitialColor, m_nColor;
CToolTipCtrl m_ToolTip;
CWnd* m_pParent;
bool m_IgnoreMouse;
CArray<CRect, const CRect&> mGroups;
CArray<CColorPopupCell, const CColorPopupCell&> mCells;

View file

@ -1,8 +1,30 @@
#include "lc_global.h"
#include "lc_colors.h"
#include "propertiesgridctrl.h"
#include "clrpopup.h"
#include "globals.h"
void CLeoCADMFCPropertyGridCtrl::SetColor(int ColorIndex)
{
ASSERT_VALID(this);
ASSERT_VALID(m_pSel);
CLeoCADMFCPropertyGridColorProperty* pColorProp = DYNAMIC_DOWNCAST(CLeoCADMFCPropertyGridColorProperty, m_pSel);
if (pColorProp == NULL)
{
ASSERT(FALSE);
return;
}
BOOL bChanged = ColorIndex != pColorProp->GetColor();
pColorProp->SetColor(ColorIndex, false);
if (bChanged)
{
OnPropertyChanged(pColorProp);
}
}
void CLeoCADMFCPropertyGridCtrl::UpdateColor(COLORREF color)
{
ASSERT_VALID(this);
@ -114,29 +136,10 @@ void CLeoCADMFCPropertyGridColorProperty::OnClickButton(CPoint /*point*/)
m_bButtonIsDown = TRUE;
Redraw();
CList<COLORREF,COLORREF> lstDocColors;
CArray<COLORREF, COLORREF> Colors;
COLORREF Color = RGB(gColorList[m_Color].Value[0] * 255, gColorList[m_Color].Value[1] * 255, gColorList[m_Color].Value[2] * 255);
for (int ColorIdx = 0; ColorIdx < gNumUserColors; ColorIdx++)
Colors.Add(RGB(gColorList[ColorIdx].Value[0] * 255, gColorList[ColorIdx].Value[1] * 255, gColorList[ColorIdx].Value[2] * 255));
m_pPopup = new CMFCColorPopupMenu(NULL, Colors, Color, NULL, NULL, NULL, lstDocColors, 7, 0);
m_pPopup->SetPropList(m_pWndList);
CPoint pt(m_pWndList->GetListRect().left + m_pWndList->GetLeftColumnWidth() + 1, m_rectButton.bottom + 1);
m_pWndList->ClientToScreen(&pt);
if (!m_pPopup->Create(m_pWndList, pt.x, pt.y, NULL, FALSE))
{
ASSERT(FALSE);
m_pPopup = NULL;
}
else
{
m_pPopup->GetMenuBar()->SetFocus();
}
new CColorPopup(pt, m_Color, m_pWndList, true);
}
BOOL CLeoCADMFCPropertyGridColorProperty::OnEdit(LPPOINT /*lptClick*/)

View file

@ -6,6 +6,7 @@ class CLeoCADMFCPropertyGridCtrl : public CMFCPropertyGridCtrl
public:
virtual void CloseColorPopup();
virtual void UpdateColor(COLORREF color);
void SetColor(int ColorIndex);
};
class CLeoCADMFCPropertyGridColorProperty : public CMFCPropertyGridProperty