// ColorPicker.h: interface for the CColorPicker class.
//
// Author : David Shepherd
// Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_COLORPICKER_H__63C4C445_6BE9_11D6_BCED_A54004CBB944__INCLUDED_)
#define AFX_COLORPICKER_H__63C4C445_6BE9_11D6_BCED_A54004CBB944__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// tab control id
#define CP_IDC_TAB_CONTROL 0x1000
// system color picker id
#define CP_IDC_SYSTEM_COLOR_PICKER 0x1001
// palette color picker id
#define CP_IDC_PALETTE_COLOR_PICKER 0x1002
// tab control message map id
#define CP_MSG_MAP_TAB_CONTROL CP_IDC_TAB_CONTROL
// system color picker message map id
#define CP_MSG_MAP_SYSTEM_COLOR_PICKER CP_IDC_SYSTEM_COLOR_PICKER
// palette color picker message map id
#define CP_MSG_MAP_PALETTE_COLOR_PICKER CP_IDC_PALETTE_COLOR_PICKER
/////////////////////////////////////////////////////////////////////////////
// CSystemColor
class CSystemColor
{
public:
// name
std::wstring m_Name;
// color
OLE_COLOR m_Color;
CSystemColor();
virtual ~CSystemColor();
};
// CSystemColor vector
typedef std::vector<CSystemColor> CSystemColorVector;
/////////////////////////////////////////////////////////////////////////////
// CPaletteColor
class CPaletteColor
{
public:
// color
OLE_COLOR m_Color;
CPaletteColor();
virtual ~CPaletteColor();
};
// CPaletteColor vector
typedef std::vector<CPaletteColor> CPaletteColorVector;
/////////////////////////////////////////////////////////////////////////////
// type definitions
// contained button
typedef CContainedWindowT<CButton> CContainedButton;
// contained list box
typedef CContainedWindowT<CListBox> CContainedListBox;
// contained tab control
typedef CContainedWindowT<CTabCtrl> CContainedTabCtrl;
/////////////////////////////////////////////////////////////////////////////
// CColorPicker
class CColorPicker : public CWindowImpl<CColorPicker>
{
private:
// tab control
CContainedTabCtrl m_TabCtrl;
// system color picker
CContainedListBox m_SystemColorPicker;
// palette color picker
CContainedButton m_PaletteColorPicker;
// system colors
CSystemColorVector m_SystemColors;
// palette colors
CPaletteColorVector m_PaletteColors;
// palette cell width
DWORD m_PaletteCellWidth;
// palette cell height
DWORD m_PaletteCellHeight;
// index of the selected palette cell
DWORD m_SelectedPaletteCellIndex;
// while TRUE this keeps the internal message loop running
BOOL m_RunMessageLoop;
// returns the color picker font
CFontHandle GetFont();
// loads system colors
void LoadSystemColors();
// loads palette colors
void LoadPaletteColors();
// sizes and positions the color picker
void SetSizeAndPosition(const CPoint &TopRight);
// selects the initial color
void SelectStartColor();
// draws the system color picker
void DrawSystemColorPicker(const DRAWITEMSTRUCT &DrawItemStruct);
// draws the palette color picker
void DrawPaletteColorPicker(const DRAWITEMSTRUCT &DrawItemStruct);
// returns the rectangle of the specified palette cell
CRect GetPaletteCellRect(DWORD PaletteCellIndex);
// determines which palette cell is located at the passed position
DWORD PaletteCellHitTest(const CPoint &Pos);
// selects the palette cell located at the passed position
void SelectPaletteCellAtPos(const CPoint &Pos);
public:
// color
OLE_COLOR m_Color;
CColorPicker();
virtual ~CColorPicker();
// shows the color picker
BOOL PickColor(const CWindow &Parent,const CPoint &TopRight);
BEGIN_MSG_MAP(CColorPicker)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem)
MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem)
MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
NOTIFY_HANDLER(CP_IDC_TAB_CONTROL, TCN_SELCHANGE, OnSelChangeTabCtrl)
COMMAND_HANDLER(CP_IDC_SYSTEM_COLOR_PICKER, LBN_SELCHANGE, OnSelChangeSystemColorPicker)
// tab control message map
ALT_MSG_MAP(CP_MSG_MAP_TAB_CONTROL)
MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
// system color picker message map
ALT_MSG_MAP(CP_MSG_MAP_SYSTEM_COLOR_PICKER)
MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
// palette color picker message map
ALT_MSG_MAP(CP_MSG_MAP_PALETTE_COLOR_PICKER)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnPaletteColorPickerLButtonDown)
MESSAGE_HANDLER(WM_LBUTTONUP, OnPaletteColorPickerLButtonUp)
MESSAGE_HANDLER(WM_MOUSEMOVE, OnPaletteColorPickerMouseMove)
MESSAGE_HANDLER(WM_RBUTTONDOWN, OnPaletteColorPickerRButtonDown)
MESSAGE_HANDLER(WM_CAPTURECHANGED, OnPaletteColorPickerCaptureChanged)
MESSAGE_HANDLER(WM_ERASEBKGND, OnPaletteColorPickerEraseBkgnd)
MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
END_MSG_MAP()
// Handler prototypes:
// LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
// LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
// LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
// message handlers
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnMeasureItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnDrawItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnSelChangeTabCtrl(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
LRESULT OnSelChangeSystemColorPicker(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
// message handlers (tab control)
// message handlers (system color picker)
// message handlers (palette color picker)
LRESULT OnPaletteColorPickerLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaletteColorPickerLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaletteColorPickerMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaletteColorPickerRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaletteColorPickerCaptureChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaletteColorPickerEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
};
#endif // !defined(AFX_COLORPICKER_H__63C4C445_6BE9_11D6_BCED_A54004CBB944__INCLUDED_)