130 lines
2.7 KiB
C++
130 lines
2.7 KiB
C++
#include "stdafx.h"
|
|
#include "InPlaceComboBox.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
static LPCTSTR SZ_SIZES[] =
|
|
{_T("1500"), _T("1800"), _T("2100"), _T("2400"), _T("2700"), _T("3000"), _T("3300"), _T("3600"), _T("3900"),
|
|
_T("4200"), _T("4500"), _T("4800"), _T("5400"), _T("6000"), _T("6600"), _T("7500"), _T("8000"), _T("9000"),NULL};
|
|
static LPCTSTR SZ_ANGLES[] =
|
|
{_T("10"), _T("15"), _T("20"), _T("25"), _T("30"), _T("35"), _T("40"), _T("45"), _T("60"), _T("90"), _T("120"), _T("150"),NULL};
|
|
|
|
CInPlaceComboBox::CInPlaceComboBox()
|
|
{
|
|
m_iItem = -1;
|
|
m_iSubItem = -1;
|
|
m_nInitFlag = 0;
|
|
m_sInitText = "";
|
|
}
|
|
|
|
CInPlaceComboBox::CInPlaceComboBox(int iItem, int iSubItem, CString sInitText)
|
|
{
|
|
m_iItem = iItem;
|
|
m_iSubItem = iSubItem;
|
|
m_nInitFlag = 0;
|
|
m_sInitText = sInitText;
|
|
}
|
|
|
|
CInPlaceComboBox::~CInPlaceComboBox()
|
|
{
|
|
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CInPlaceComboBox, CComboBox)
|
|
//{{AFX_MSG_MAP(CInPlaceComboBox)
|
|
ON_WM_NCDESTROY()
|
|
ON_WM_CREATE()
|
|
ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
|
|
ON_CONTROL_REFLECT(CBN_KILLFOCUS, OnCbnKillfocus)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CInPlaceComboBox::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
if (pMsg->message == WM_KEYDOWN)
|
|
{
|
|
int nVK = (int) pMsg->wParam;
|
|
if (nVK == VK_RETURN)
|
|
{
|
|
OnCbnKillfocus();
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
return CComboBox::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
void CInPlaceComboBox::OnNcDestroy()
|
|
{
|
|
CComboBox::OnNcDestroy();
|
|
}
|
|
|
|
int CInPlaceComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
{
|
|
if (CComboBox::OnCreate(lpCreateStruct) == -1)
|
|
return -1;
|
|
|
|
CFont* font = GetParent()->GetFont();
|
|
SetFont(font);
|
|
|
|
if (m_iSubItem == 0)
|
|
{
|
|
int i = 0;
|
|
LPCTSTR* ppszText = (m_nInitFlag == 1) ? SZ_ANGLES : SZ_SIZES;
|
|
while(TRUE && ppszText != NULL)
|
|
{
|
|
if (ppszText[i] == NULL) break;
|
|
AddString(ppszText[i]);
|
|
i += 1;
|
|
}
|
|
}
|
|
|
|
if (m_iSubItem == 1)
|
|
{
|
|
CString sText;
|
|
for(int i = 1;i < 19;i++)
|
|
{
|
|
sText.Format(_T("%d"),i);
|
|
AddString(sText);
|
|
}
|
|
}
|
|
|
|
int nSel = FindString(0,m_sInitText);
|
|
if (nSel != -1) SetCurSel(nSel);
|
|
|
|
SetWindowText( m_sInitText );
|
|
SetEditSel(0,-1);
|
|
return 0;
|
|
}
|
|
|
|
void CInPlaceComboBox::OnSelchange()
|
|
{
|
|
PostMessage(WM_CLOSE);
|
|
}
|
|
|
|
void CInPlaceComboBox::OnCbnKillfocus()
|
|
{
|
|
CString str;
|
|
GetWindowText(str);
|
|
|
|
LV_DISPINFO dispinfo;
|
|
dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
|
|
dispinfo.hdr.idFrom = GetDlgCtrlID();
|
|
dispinfo.hdr.code = LVN_ENDLABELEDIT;
|
|
|
|
dispinfo.item.mask = LVIF_TEXT;
|
|
dispinfo.item.iItem = m_iItem;
|
|
dispinfo.item.iSubItem = m_iSubItem;
|
|
dispinfo.item.pszText = LPTSTR((LPCTSTR)str);
|
|
dispinfo.item.cchTextMax = str.GetLength();
|
|
|
|
GetParent()->SendMessage( WM_NOTIFY, GetParent()->GetDlgCtrlID(),
|
|
(LPARAM)&dispinfo );
|
|
|
|
DestroyWindow();
|
|
}
|