00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016 #include "stdafx.h"
00017 #include "../GridCtrl_src/GridCtrl.h"
00018 #include "../GridCtrl_src/GridCell.h"
00019 #include "GridCellDouble.h"
00020
00021 #ifdef _DEBUG
00022 #undef THIS_FILE
00023 static char THIS_FILE[]=__FILE__;
00024 #define new DEBUG_NEW
00025 #endif
00026
00028
00029
00030 IMPLEMENT_DYNCREATE(CGridCellDouble, CGridCell)
00031
00032
00033
00035
00036 CGridCellDouble::CGridCellDouble() : CGridCell()
00037 {
00038 m_dwStyle = 0;
00039 }
00040
00041
00042 CGridCellDouble::~CGridCellDouble()
00043 {
00044 }
00045
00046 BOOL CGridCellDouble::Edit(int nRow, int nCol, CRect rect, CPoint , UINT nID, UINT nChar)
00047 {
00048 if ( m_bEditing )
00049 {
00050 if (m_pEditWnd)
00051 m_pEditWnd->SendMessage ( WM_CHAR, nChar );
00052 }
00053 else
00054 {
00055 DWORD dwStyle = ES_LEFT;
00056 if (GetFormat() & DT_RIGHT)
00057 dwStyle = ES_RIGHT;
00058 else if (GetFormat() & DT_CENTER)
00059 dwStyle = ES_CENTER;
00060
00061 m_bEditing = TRUE;
00062
00063
00064 CGridCtrl* pGrid = GetGrid();
00065 m_pEditWnd = new CInPlaceDoubleEdit(pGrid, rect, dwStyle, nID, nRow, nCol, GetText(), nChar);
00066 }
00067 return TRUE;
00068 }
00069
00070
00072
00073
00074
00075 CInPlaceDoubleEdit::CInPlaceDoubleEdit(CWnd* pParent, CRect& rect, DWORD dwStyle, UINT nID,
00076 int nRow, int nColumn, CString sInitText,
00077 UINT nFirstChar):CInPlaceEdit(pParent, rect, dwStyle, nID,
00078 nRow, nColumn, sInitText,
00079 nFirstChar)
00080 {
00081
00082
00083 }
00084
00085
00086 BEGIN_MESSAGE_MAP(CInPlaceDoubleEdit, CInPlaceEdit)
00087
00088 ON_WM_CHAR()
00089
00090 END_MESSAGE_MAP()
00091
00092
00093
00094
00095 void CInPlaceDoubleEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
00096 {
00097
00098
00099 if (nChar == VK_TAB || nChar == VK_RETURN || nChar == VK_ESCAPE ||
00100 nChar == 127 || nChar == VK_BACK)
00101 {
00102 CInPlaceEdit::OnChar(nChar, nRepCnt, nFlags);
00103 return;
00104 }
00105
00106
00107 if ((nChar >= '0') && (nChar <= '9'))
00108 {
00109 CInPlaceEdit::OnChar(nChar, nRepCnt, nFlags);
00110 return;
00111 }
00112
00113
00114 CString currentText;
00115 this->GetWindowText(currentText.GetBuffer(100),100);
00116
00117 if (nChar == '.')
00118 {
00119 if (currentText.FindOneOf(".") != -1)
00120 {
00121
00122 return;
00123 }
00124 else
00125 {
00126
00127 CInPlaceEdit::OnChar(nChar, nRepCnt, nFlags);
00128 return;
00129 }
00130 }
00131
00132 if (nChar == '-')
00133 {
00134 if (currentText.FindOneOf("-") != -1)
00135 {
00136
00137 return;
00138 }
00139 else
00140 {
00141
00142 this->SetSel(0,0);
00143 CInPlaceEdit::OnChar(nChar, nRepCnt, nFlags);
00144 return;
00145 }
00146 }
00147
00148 }
00149
00150
00151