📄 formitemcombo.cpp
字号:
// FormItemCombo.cpp: implementation of the CFormItemCombo class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FormListCtrl.h"
#include "FormItemCombo.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
using namespace DRA;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFormItemCombo::CFormItemCombo()
: m_iVal (-1)
{
}
CFormItemCombo::~CFormItemCombo()
{
}
// CFormItemCombo::SetSelData
//
// Selects the item using the data
//
void CFormItemCombo::SetSelData(DWORD dwData)
{
size_t i;
m_iVal = -1;
for(i = 0; m_iVal == -1 && i < m_data.size(); ++i)
if(m_data[i].m_dwData == dwData)
m_iVal = (int)i;
}
// CFormItemCombo::RenderData
//
// Data rendering for strings
//
LPCTSTR CFormItemCombo::RenderData(LV_DISPINFO *pDispInfo)
{
LPCTSTR pszData = _T("");
int iSubItem;
if(!pDispInfo) // If pointer is NULL
iSubItem = 1; // Assume rendering data
else
iSubItem = pDispInfo->item.iSubItem;
if(iSubItem == 1)
{
//
// Render the data
//
if(m_iVal != -1)
pszData = m_data[m_iVal].m_strData;
}
else
{
//
// Render the caption
//
pszData = CFormItem::RenderData(pDispInfo);
}
return pszData;
}
// CFormItemCombo::ValidateData
//
// Checks if the data is valid
//
BOOL CFormItemCombo::ValidateData()
{
BOOL bOk = TRUE;
if(IsMandatory())
bOk = (m_iVal != -1);
return bOk;
}
// CFormItemCombo::ShowEditor
//
// Displays the combo box control
//
BOOL CFormItemCombo::ShowEditor(CFormListCtrl* pForm, BOOL bShow, int iItem, int iSubItem)
{
BOOL bOk = FALSE;
ASSERT(pForm);
if(bShow)
{
CRect rc;
if(pForm->GetSubItemRect(iItem, 1, rc))
{
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST;
//
// Create the combo control
//
rc.left += SCALEX(3);
rc.top -= SCALEY(1);
rc.bottom += rc.Height() * 4;
if(m_wndCombo.Create(dwStyle, rc, pForm, IDC_FORM_ITEM))
{
size_t i;
int iItem;
//
// Setup the combo box control
//
m_wndCombo.SetFont(pForm->GetContentFont());
for(i = 0; i < m_data.size(); ++i)
{
iItem = m_wndCombo.AddString(m_data[i].m_strData);
if(iItem != CB_ERR)
m_wndCombo.SetItemData(iItem, m_data[i].m_dwData);
}
m_wndCombo.SetFocus();
m_wndCombo.SetCurSel(m_iVal);
m_wndCombo.ShowDropDown();
bOk = TRUE;
}
}
}
else
{
if(IsWindow(m_wndCombo))
{
m_iVal = m_wndCombo.GetCurSel();
if(ValidateData())
{
m_wndCombo.DestroyWindow();
bOk = TRUE;
}
}
}
return bOk;
}
// CFormItemCombo::MoveEditor
//
// Move the combo to the new rect
//
void CFormItemCombo::MoveEditor(const RECT &rcItem)
{
if(IsWindow(m_wndCombo))
{
CRect rc(rcItem);
rc.left += SCALEX(3);
rc.top -= SCALEY(1);
rc.bottom += rc.Height() * 4;
m_wndCombo.MoveWindow(&rc, FALSE);
}
}
// CFormItemCombo::OnCtrlNotify
//
// Handles the combo box notifications
//
BOOL CFormItemCombo::OnCtrlNotify(CFormListCtrl* pForm, int iItem, WORD wNotify)
{
if(wNotify == CBN_SELCHANGE)
{
m_iVal = m_wndCombo.GetCurSel();
pForm->ItemUpdated(this, 0);
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -