/** * @file XTPMaskEdit.cpp * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #include "stdafx.h" #include "Common/XTPTypeId.h" #include "Common/XTPCasting.h" #include "Common/XTPFramework.h" #include "Common/XTPVC80Helpers.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/XTPGdiObjects.h" #include "Common/XTPMaskEditT.h" #include "Common/ScrollBar/XTPScrollBase.h" #include "Common/ScrollBar/XTPScrollBarCtrl.h" #include "Common/ScrollBar/XTPScrollable.h" #include "Controls/Util/XTPControlTheme.h" #include "Controls/Util/XTPGlobal.h" #include "Controls/Edit/XTPEdit.h" #include "Controls/Edit/XTPMaskEdit.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CXTPMaskEdit ///////////////////////////////////////////////////////////////////////////// CXTPMaskEdit::CXTPMaskEdit() { } IMPLEMENT_DYNAMIC(CXTPMaskEdit, CXTPEdit) bool CXTPMaskEdit::Initialize(CWnd* /*pParentWnd*/) { SetFont(&XTPAuxData().xtpFont); return true; } ///////////////////////////////////////////////////////////////////////////// // CXTPDateEdit class ///////////////////////////////////////////////////////////////////////////// CXTPDateEdit::CXTPDateEdit() { m_bUseMask = true; m_strMask = _T("00/00/0000"); m_strLiteral = _T("__/__/____"); m_strDefault = _T("00/00/0000"); } COleDateTime CXTPDateEdit::ReadOleDateTime(LPCTSTR lpszData) { COleDateTime dt; dt.ParseDateTime(lpszData); return dt; } IMPLEMENT_DYNAMIC(CXTPDateEdit, CXTPMaskEdit) void CXTPDateEdit::FormatOleDateTime(CString& strData, COleDateTime dt) { strData = dt.Format(_T("%d/%m/%Y")); } void CXTPDateEdit::SetDateTime(COleDateTime& dt) { CString strText; FormatOleDateTime(strText, dt); m_strWindowText = m_strDefault = strText; SetWindowText(strText); } void CXTPDateEdit::SetDateTime(LPCTSTR strDate) { m_strWindowText = m_strDefault = strDate; SetWindowText(strDate); } COleDateTime CXTPDateEdit::GetDateTime() { CString strText; GetWindowText(strText); return ReadOleDateTime(strText); } CString CXTPDateEdit::GetWindowDateTime() { CString strText; GetWindowText(strText); return strText; } BOOL CXTPDateEdit::ProcessMask(TCHAR& nChar, int nEndPos) { // check the key against the mask if (m_strMask[nEndPos] == _T('0') && _istdigit(XTP_CHARTOCRT(nChar))) { // Allow d/m/y and m/d/y if (nEndPos == 0 || nEndPos == 3) { if (nChar > '3') return FALSE; } if (nEndPos == 1 || nEndPos == 4) { if (m_strWindowText.GetAt(0) == _T('3')) { if (nChar > _T('1')) return FALSE; } } return TRUE; } return FALSE; } ///////////////////////////////////////////////////////////////////////////// // CXTPTimeEdit class ///////////////////////////////////////////////////////////////////////////// CXTPTimeEdit::CXTPTimeEdit() { m_bMilitary = false; m_bUseMask = true; m_strMask = _T("00:00"); m_strLiteral = _T("__:__"); m_strDefault = _T("00:00"); m_iHours = 0; m_iMins = 0; } IMPLEMENT_DYNAMIC(CXTPTimeEdit, CXTPDateEdit) void CXTPTimeEdit::FormatOleDateTime(CString& strData, COleDateTime dt) { if (dt.m_dt == 0) { strData = _T("00:00"); } else { strData = dt.Format(_T("%H:%M")); } } BOOL CXTPTimeEdit::ProcessMask(TCHAR& nChar, int nEndPos) { // check the key against the mask if (m_strMask[nEndPos] == _T('0') && _istdigit(XTP_CHARTOCRT(nChar))) { switch (nEndPos) { case 0: if (m_bMilitary) { if (nChar > _T('2')) return FALSE; } else { if (nChar > _T('1')) return FALSE; } return TRUE; case 1: if (m_bMilitary) { if (m_strWindowText.GetAt(0) == _T('2')) { if (nChar > _T('3')) return FALSE; } } else { if (m_strWindowText.GetAt(0) == _T('1')) { if (nChar > _T('2')) return FALSE; } } return TRUE; case 3: if (nChar > _T('5')) return FALSE; return TRUE; case 4: return TRUE; } } return FALSE; } void CXTPTimeEdit::SetHours(int nHours) { m_iHours = nHours; CString strText; strText.Format(_T("%02d:%02d"), m_iHours, m_iMins); SetWindowText(strText); } void CXTPTimeEdit::SetMins(int nMins) { m_iMins = nMins; CString strText; strText.Format(_T("%02d:%02d"), m_iHours, m_iMins); SetWindowText(strText); } void CXTPTimeEdit::SetTime(int nHours, int nMins) { m_iHours = nHours; m_iMins = nMins; CString strText; strText.Format(_T("%02d:%02d"), m_iHours, m_iMins); SetWindowText(strText); } ///////////////////////////////////////////////////////////////////////////// // DDX_ routines ///////////////////////////////////////////////////////////////////////////// _XTP_EXT_CLASS void AFXAPI DDX_XTPOleDateTime(CDataExchange* pDX, int nIDC, CXTPDateEdit& rControl, COleDateTime& rDateTime) { DDX_Control(pDX, nIDC, rControl); if (pDX->m_bSaveAndValidate) { rDateTime = rControl.GetDateTime(); } else { rControl.SetDateTime(rDateTime); } }