00001
00002
00003
00004 #include "stdafx.h"
00005 #include "inplacelist.h"
00006
00007
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #undef THIS_FILE
00011 static char THIS_FILE[] = __FILE__;
00012 #endif
00013
00015
00016
00017 CInPlaceList::CInPlaceList(int iItem, int iSubItem, CStringList *plstItems, int nSel)
00018 {
00019 m_iItem = iItem;
00020 m_iSubItem = iSubItem;
00021
00022 m_lstItems.AddTail( plstItems );
00023 m_nSel = nSel;
00024 m_bESC = FALSE;
00025 }
00026
00027 CInPlaceList::~CInPlaceList()
00028 {
00029 }
00030
00031
00032 BEGIN_MESSAGE_MAP(CInPlaceList, CComboBox)
00033
00034 ON_WM_CREATE()
00035 ON_WM_KILLFOCUS()
00036 ON_WM_CHAR()
00037 ON_WM_NCDESTROY()
00038 ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup)
00039
00040 END_MESSAGE_MAP()
00041
00043
00044
00045 int CInPlaceList::OnCreate(LPCREATESTRUCT lpCreateStruct)
00046 {
00047 if (CComboBox::OnCreate(lpCreateStruct) == -1)
00048 return -1;
00049
00050
00051 CFont* font = GetParent()->GetFont();
00052 SetFont(font);
00053
00054 for( POSITION pos = m_lstItems.GetHeadPosition(); pos != NULL; )
00055 {
00056 AddString( (LPCTSTR) (m_lstItems.GetNext( pos )) );
00057 }
00058 SetCurSel( m_nSel );
00059 SetFocus();
00060 return 0;
00061 }
00062
00063 BOOL CInPlaceList::PreTranslateMessage(MSG* pMsg)
00064 {
00065 if( pMsg->message == WM_KEYDOWN )
00066 {
00067 if(pMsg->wParam == VK_RETURN
00068 || pMsg->wParam == VK_ESCAPE
00069 )
00070 {
00071 ::TranslateMessage(pMsg);
00072 ::DispatchMessage(pMsg);
00073 return TRUE;
00074 }
00075 }
00076
00077 return CComboBox::PreTranslateMessage(pMsg);
00078 }
00079
00080 void CInPlaceList::OnKillFocus(CWnd* pNewWnd)
00081 {
00082 CComboBox::OnKillFocus(pNewWnd);
00083
00084 CString str;
00085 GetWindowText(str);
00086
00087
00088 LV_DISPINFO dispinfo;
00089 dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
00090 dispinfo.hdr.idFrom = GetDlgCtrlID();
00091 dispinfo.hdr.code = LVN_ENDLABELEDIT;
00092
00093 dispinfo.item.mask = LVIF_TEXT;
00094 dispinfo.item.iItem = m_iItem;
00095 dispinfo.item.iSubItem = m_iSubItem;
00096 dispinfo.item.pszText = m_bESC ? NULL : LPTSTR((LPCTSTR)str);
00097 dispinfo.item.cchTextMax = str.GetLength();
00098
00099 GetParent()->GetParent()->SendMessage( WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&dispinfo );
00100
00101 PostMessage( WM_CLOSE );
00102 }
00103
00104 void CInPlaceList::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
00105 {
00106 if( nChar == VK_ESCAPE || nChar == VK_RETURN)
00107 {
00108 if( nChar == VK_ESCAPE )
00109 m_bESC = TRUE;
00110 GetParent()->SetFocus();
00111 return;
00112 }
00113
00114 CComboBox::OnChar(nChar, nRepCnt, nFlags);
00115 }
00116
00117 void CInPlaceList::OnNcDestroy()
00118 {
00119 CComboBox::OnNcDestroy();
00120
00121 delete this;
00122 }
00123
00124 void CInPlaceList::OnCloseup()
00125 {
00126 GetParent()->SetFocus();
00127 }