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 "GridCellDateTime.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(CGridCellDateTime, CGridCell)
00031
00032
00033
00035
00036 CGridCellDateTime::CGridCellDateTime() : CGridCell()
00037 {
00038 m_dwStyle = 0;
00039 m_cTime = CTime::GetCurrentTime();
00040 }
00041
00042 CGridCellDateTime::CGridCellDateTime(DWORD dwStyle) : CGridCell()
00043 {
00044 Init(dwStyle);
00045 }
00046
00047 CGridCellDateTime::~CGridCellDateTime()
00048 {
00049 }
00050
00051 BOOL CGridCellDateTime::Edit(int nRow, int nCol, CRect rect, CPoint ,
00052 UINT nID, UINT nChar)
00053 {
00054 m_bEditing = TRUE;
00055
00056
00057 m_pEditWnd = new CInPlaceDateTime(GetGrid(), rect,
00058 m_dwStyle|DTS_UPDOWN, nID, nRow, nCol,
00059 GetTextClr(), GetBackClr(), GetTime(), nChar);
00060 return TRUE;
00061 }
00062
00063 CWnd* CGridCellDateTime::GetEditWnd() const
00064 {
00065 return m_pEditWnd;
00066 }
00067
00068 void CGridCellDateTime::EndEdit()
00069 {
00070 if (m_pEditWnd) ((CInPlaceDateTime*)m_pEditWnd)->EndEdit();
00071 }
00072
00073 void CGridCellDateTime::Init(DWORD dwStyle)
00074 {
00075 m_dwStyle = dwStyle;
00076
00077 SetTime(CTime::GetCurrentTime());
00078
00079 SetFormat(DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX
00080 #ifndef _WIN32_WCE
00081 |DT_END_ELLIPSIS
00082 #endif
00083 );
00084 }
00085
00086
00087 void CGridCellDateTime::SetTime(CTime time)
00088 {
00089 m_cTime = time;
00090
00091 if (DTS_TIMEFORMAT == m_dwStyle)
00092 {
00093 #ifdef _WIN32_WCE
00094 CString strTemp;
00095 strTemp.Format(_T("%02d:%02d:%02d"),
00096 m_cTime.GetHour(), m_cTime.GetMinute(), m_cTime.GetSecond());
00097 SetText(strTemp);
00098 #else
00099 SetText(m_cTime.Format(_T("%H:%M:%S")));
00100 #endif
00101 }
00102 else if (DTS_SHORTDATEFORMAT == m_dwStyle)
00103 {
00104 #ifdef _WIN32_WCE
00105 CString strTemp;
00106 strTemp.Format(_T("%02d/%02d/%02d"),
00107 m_cTime.GetMonth(), m_cTime.GetDay(), m_cTime.GetYear());
00108 SetText(strTemp);
00109 #else
00110 SetText(m_cTime.Format(("%d/%m/%Y")));
00111 #endif
00112 }
00113 }
00114
00116
00117
00118 CInPlaceDateTime::CInPlaceDateTime(CWnd* pParent, CRect& rect, DWORD dwStyle, UINT nID,
00119 int nRow, int nColumn,
00120 COLORREF crFore, COLORREF crBack,
00121 CTime* pcTime,
00122 UINT nFirstChar)
00123 {
00124 m_crForeClr = crFore;
00125 m_crBackClr = crBack;
00126 m_nRow = nRow;
00127 m_nCol = nColumn;
00128 m_nLastChar = 0;
00129 m_bExitOnArrows = FALSE;
00130 m_pcTime = pcTime;
00131
00132 DWORD dwStl = WS_BORDER|WS_VISIBLE|WS_CHILD|dwStyle;
00133
00134 if (!Create(dwStl, rect, pParent, nID)) {
00135 return;
00136 }
00137
00138 SetTime(m_pcTime);
00139
00140 SetFont(pParent->GetFont());
00141 SetFocus();
00142
00143 switch (nFirstChar)
00144 {
00145 case VK_LBUTTON:
00146 case VK_RETURN: return;
00147 case VK_BACK: break;
00148 case VK_DOWN:
00149 case VK_UP:
00150 case VK_RIGHT:
00151 case VK_LEFT:
00152 case VK_NEXT:
00153 case VK_PRIOR:
00154 case VK_HOME:
00155 case VK_END: return;
00156 default: break;
00157 }
00158 SendMessage(WM_CHAR, nFirstChar);
00159 }
00160
00161 CInPlaceDateTime::~CInPlaceDateTime()
00162 {
00163 }
00164
00165 void CInPlaceDateTime::EndEdit()
00166 {
00167 CString str;
00168 if (::IsWindow(m_hWnd))
00169 {
00170 GetWindowText(str);
00171 GetTime(*m_pcTime);
00172 }
00173
00174
00175 GV_DISPINFO dispinfo;
00176
00177 dispinfo.hdr.hwndFrom = GetSafeHwnd();
00178 dispinfo.hdr.idFrom = GetDlgCtrlID();
00179 dispinfo.hdr.code = GVN_ENDLABELEDIT;
00180
00181 dispinfo.item.mask = LVIF_TEXT|LVIF_PARAM;
00182 dispinfo.item.row = m_nRow;
00183 dispinfo.item.col = m_nCol;
00184 dispinfo.item.strText = str;
00185 dispinfo.item.lParam = (LPARAM) m_nLastChar;
00186
00187 CWnd* pOwner = GetOwner();
00188 if (IsWindow(pOwner->GetSafeHwnd())) {
00189 pOwner->SendMessage(WM_NOTIFY, GetDlgCtrlID(), (LPARAM)&dispinfo);
00190 }
00191
00192
00193 if (::IsWindow(m_hWnd)) {
00194 PostMessage(WM_CLOSE, 0, 0);
00195 }
00196 }
00197
00198 void CInPlaceDateTime::PostNcDestroy()
00199 {
00200 CDateTimeCtrl::PostNcDestroy();
00201 delete this;
00202 }
00203
00204 BEGIN_MESSAGE_MAP(CInPlaceDateTime, CDateTimeCtrl)
00205
00206 ON_WM_KILLFOCUS()
00207 ON_WM_KEYDOWN()
00208 ON_WM_KEYUP()
00209 ON_WM_GETDLGCODE()
00210
00211 END_MESSAGE_MAP()
00212
00213
00215
00216
00217 void CInPlaceDateTime::OnKillFocus(CWnd* pNewWnd)
00218 {
00219 CDateTimeCtrl::OnKillFocus(pNewWnd);
00220
00221 if (GetSafeHwnd() == pNewWnd->GetSafeHwnd()) {
00222 return;
00223 }
00224 EndEdit();
00225 }
00226
00227 UINT CInPlaceDateTime::OnGetDlgCode()
00228 {
00229 return DLGC_WANTALLKEYS;
00230 }
00231
00232 void CInPlaceDateTime::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
00233 {
00234 if (( nChar == VK_PRIOR || nChar == VK_NEXT ||
00235 nChar == VK_DOWN || nChar == VK_UP ||
00236 nChar == VK_RIGHT || nChar == VK_LEFT) &&
00237 (m_bExitOnArrows || GetKeyState(VK_CONTROL) < 0))
00238 {
00239 m_nLastChar = nChar;
00240 GetParent()->SetFocus();
00241 return;
00242 }
00243
00244 CDateTimeCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
00245 }
00246
00247 void CInPlaceDateTime::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
00248 {
00249 if (nChar == VK_TAB || nChar == VK_RETURN || nChar == VK_ESCAPE)
00250 {
00251 m_nLastChar = nChar;
00252 GetParent()->SetFocus();
00253 return;
00254 }
00255
00256 CDateTimeCtrl::OnKeyUp(nChar, nRepCnt, nFlags);
00257 }