📄 formitemstring.cpp
字号:
// FormItemString.cpp: implementation of the CFormItemString class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FormItemString.h"
#include "FormListCtrl.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFormItemString::CFormItemString()
{
}
CFormItemString::~CFormItemString()
{
}
// CFormItemString::RenderData
//
// Data rendering for strings
//
LPCTSTR CFormItemString::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
//
pszData = m_strVal;
}
else
{
//
// Render the caption
//
pszData = CFormItem::RenderData(pDispInfo);
}
return pszData;
}
// CFormItemString::ValidateData
//
// Validates the string data
//
BOOL CFormItemString::ValidateData()
{
BOOL bOk = TRUE;
if(IsMandatory())
bOk = !m_strVal.IsEmpty();
return bOk;
}
void CFormItemString::GetControlData()
{
if(IsWindow(m_wndEdit))
m_wndEdit.GetWindowText(m_strVal);
}
// CFormItemString::ShowEditor
//
// Displays the edit control
//
BOOL CFormItemString::ShowEditor(CFormListCtrl* pForm, BOOL bShow, int iItem, int iSubItem)
{
BOOL bOk = FALSE;
ASSERT(pForm);
if(bShow)
{
RECT rc;
// Check if the window is created
if(IsWindow(m_wndEdit))
return FALSE;
if(pForm->GetSubItemRect(iItem, 1, rc))
{
DWORD dwStyle = WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_LEFT;
//
// Create the edit control
//
rc.left += 6;
rc.top++;
rc.bottom--;
if(m_wndEdit.Create(dwStyle, rc, pForm, IDC_FORM_ITEM))
{
//
// Setup the edit control
//
m_wndEdit.SetWindowText(m_strVal);
m_wndEdit.SetFont(pForm->GetContentFont());
m_wndEdit.SetFocus();
m_wndEdit.SetSel(0, -1);
SHSipPreference(*pForm, SIP_UP);
bOk = TRUE;
}
}
}
else
{
if(IsWindow(m_wndEdit))
{
m_wndEdit.GetWindowText(m_strVal);
SHSipPreference(*pForm, SIP_DOWN);
m_wndEdit.DestroyWindow();
bOk = TRUE;
}
}
return bOk;
}
// CFormItemString::Select
//
// Overriden selection method
// When a string item is selected it immediately shows the editor control
//
BOOL CFormItemString::Select(CFormListCtrl *pForm, BOOL bSelect, int iItem)
{
BOOL bOk;
// Call base class
//CFormItem::Select(pForm, bSelect, iItem);
if(bSelect)
pForm->SetEditIndex(iItem);
bOk = ShowEditor(pForm, bSelect, iItem, 1);
if(bOk)
pForm->RedrawItems(iItem, iItem);
return bOk;
}
// CFormItemString::MoveEditor
//
// Move the editor to the new rect
//
void CFormItemString::MoveEditor(const RECT &rcItem)
{
if(IsWindow(m_wndEdit))
{
CRect rc(rcItem);
rc.left += 6;
rc.top++;
rc.bottom--;
m_wndEdit.MoveWindow(&rc, FALSE);
}
}
// CFormItemString::OnCmdMsg
//
// Handles editor command messages
//
BOOL CFormItemString::OnCmdMsg(UINT nID, int nCode, void *pExtra, AFX_CMDHANDLERINFO *pHandlerInfo)
{
if(IsWindow(m_wndEdit))
return m_wndEdit.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -