PageMaskedEdit.h
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:13k
源码类别:

界面编程

开发平台:

Visual C++

  1. #if !defined(__PAGE_MASKED_EDIT_H)
  2. #define __PAGE_MASKED_EDIT_H
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif // _MSC_VER > 1000
  6. // PageMaskedEdit.h : header file
  7. //
  8. #include "PageBase.h"
  9. #if (!defined __EXT_MFC_NO_GRIDWND )
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CPageMaskedEdit dialog
  12. class CPageMaskedEdit : public CPageBase 
  13. {
  14. public:
  15. CPageMaskedEdit(CWnd* pParent = NULL);   // standard constructor
  16. //{{AFX_DATA(CPageMaskedEdit)
  17. enum { IDD = IDD_PAGE_MASKED_EDIT };
  18. CExtCheckBox m_checkModeNullable;
  19. CExtCheckBox m_checkModeInsert;
  20. CExtCheckBox m_checkModeFieldSelection;
  21. CExtEditMasked m_editTextMaskedSimple;
  22. CExtEditMasked m_editTextMaskedRich;
  23. CExtCheckBox m_checkUseMaskedRichEdit;
  24. //}}AFX_DATA
  25. class CRuleGridWnd : public CExtNSB < CExtGridWnd >
  26. {
  27. public:
  28. CExtEditMasked * m_pEditWithBehaviorWnd;
  29. CRuleGridWnd()
  30. : m_pEditWithBehaviorWnd( NULL )
  31. {
  32. }
  33. protected:
  34. virtual void PreSubclassWindow()
  35. {
  36. CExtNSB < CExtGridWnd > :: PreSubclassWindow();
  37. SiwModifyStyle( __ESIS_STH_NONE|__ESIS_STV_PIXEL|__EGBS_SFB_CELLS|__EGBS_GRIDLINES|__EGBS_NO_HIDE_SELECTION
  38. |__EGBS_DYNAMIC_RESIZING_H|__EGBS_RESIZING_CELLS_INNER_H|__EGBS_RESIZING_CELLS_OUTER_H, 0, false );
  39. SiwModifyStyleEx( __EGWS_EX_PM_COLORS|__EGBS_EX_CELL_TOOLTIPS_OUTER|__EGBS_EX_CELL_EXPANDING_INNER, 0, false );
  40. BseModifyStyle( __EGWS_BSE_EDIT_CELLS_INNER, 0, false );
  41. BseModifyStyleEx( __EGBS_BSE_EX_PROPORTIONAL_COLUMN_WIDTHS|__EGBS_BSE_EX_EAL_BOTTOM_V, 0, false );
  42. OuterRowCountTopSet( 1L, false );
  43. ColumnAdd( 5L, false );
  44. CExtGridCell * pCell = NULL;
  45. // header cell 1
  46. pCell = GridCellGetOuterAtTop( 0L, 0L, RUNTIME_CLASS(CExtGridCellHeader) );
  47. pCell->TextSet( _T("Rule status") );
  48. pCell->ExtentPercentSet( 0.25 );
  49. // header cell 2
  50. pCell = GridCellGetOuterAtTop( 1L, 0L, RUNTIME_CLASS(CExtGridCellHeader) );
  51. pCell->TextSet( _T("One character") );
  52. pCell->ExtentPercentSet( 0.05 );
  53. // header cell 3
  54. pCell = GridCellGetOuterAtTop( 2L, 0L, RUNTIME_CLASS(CExtGridCellHeader) );
  55. pCell->TextSet( _T("Validation Function") );
  56. pCell->ExtentPercentSet( 0.35 );
  57. // header cell 4
  58. pCell = GridCellGetOuterAtTop( 3L, 0L, RUNTIME_CLASS(CExtGridCellHeader) );
  59. pCell->TextSet( _T("Conversion Function") );
  60. pCell->ExtentPercentSet( 0.35 );
  61. // header cell 5
  62. pCell = GridCellGetOuterAtTop( 4L, 0L, RUNTIME_CLASS(CExtGridCellHeader) );
  63. pCell->TextSet( _T("Color (rich edit mode only)") );
  64. pCell->ExtentPercentSet( 0.35 );
  65. // finish init
  66. OnSwUpdateScrollBars();
  67. }
  68. public:
  69. virtual void OnRuleSetChanged()
  70. {
  71. ASSERT_VALID( this );
  72. if( m_pEditWithBehaviorWnd->GetSafeHwnd() == NULL )
  73. return;
  74. ASSERT_VALID( m_pEditWithBehaviorWnd );
  75. m_pEditWithBehaviorWnd->m_arrRules.RemoveAll();
  76. LONG nRuleIndex, nRuleCount = RowCountGet();
  77. for( nRuleIndex = 0L; nRuleIndex < nRuleCount; nRuleIndex ++ )
  78. {
  79. CExtEditWithBehavior::CBehaviorMasked::CharRule _cr;
  80. if( ! RuleGetAt( nRuleIndex, _cr ) )
  81. continue;
  82. m_pEditWithBehaviorWnd->m_arrRules.Add( _cr );
  83. }
  84. CExtSafeString strTextValid = m_pEditWithBehaviorWnd->TextGetValid();
  85. LPCTSTR strTextToSet = (LPCTSTR(strTextValid) != NULL) ? LPCTSTR(strTextValid) : _T("");
  86. if( m_pEditWithBehaviorWnd->m_bRichMode )
  87. {
  88. CExtSafeString strSet( strTextToSet );
  89. m_pEditWithBehaviorWnd->Rich_PlainText_Set( strSet );
  90. m_pEditWithBehaviorWnd->_Rich_OnDraw();
  91. }
  92. else
  93. m_pEditWithBehaviorWnd->SetWindowText( strTextToSet );
  94. m_pEditWithBehaviorWnd->SetSel( -1, -1 );
  95. }
  96. virtual void OnGridCellInputComplete(
  97. CExtGridCell & _cell,
  98. LONG nColNo,
  99. LONG nRowNo,
  100. INT nColType,
  101. INT nRowType,
  102. HWND hWndInputControl = NULL
  103. )
  104. {
  105. CExtNSB < CExtGridWnd > :: OnGridCellInputComplete( _cell, nColNo, nRowNo, nColType, nRowType, hWndInputControl );
  106. OnRuleSetChanged();
  107. }
  108. void RuleAdd(
  109. bool bEnabled,
  110. CExtEditWithBehavior::CBehaviorMasked::CharRule & _cr,
  111. __EXT_MFC_SAFE_LPCTSTR strFunctionNameValidation,
  112. __EXT_MFC_SAFE_LPCTSTR strFunctionNameConversion
  113. )
  114. {
  115. ASSERT_VALID( this );
  116. LONG nRuleIndex = RowCountGet();
  117. RowAdd( 1L, false );
  118. CExtGridCellBool * pCellStatus =
  119. STATIC_DOWNCAST(
  120. CExtGridCellBool,
  121. GridCellGet( 0L, nRuleIndex, 0, 0, RUNTIME_CLASS(CExtGridCellBool) )
  122. );
  123. pCellStatus->LabelTextSet( true, _T("Enabled") );
  124. pCellStatus->LabelTextSet( false, _T("Disabled") );
  125. pCellStatus->DataSet( bEnabled );
  126. pCellStatus->ModifyStyle( __EGCS_NO_INPLACE_CONTROL );
  127. CExtGridCellString * pCellOneCharacter =
  128. STATIC_DOWNCAST(
  129. CExtGridCellString,
  130. GridCellGet( 1L, nRuleIndex, 0, 0, RUNTIME_CLASS(CExtGridCellString) )
  131. );
  132. pCellOneCharacter->ModifyStyle( __EGCS_TA_HORZ_CENTER );
  133. TCHAR strTmp[ 2 ] = { _cr.Get(), _T('') };
  134. pCellOneCharacter->TextSet( strTmp );
  135. CExtGridCellComboBox * pCellValidationFunction =
  136. STATIC_DOWNCAST(
  137. CExtGridCellComboBox,
  138. GridCellGet( 2L, nRuleIndex, 0, 0, RUNTIME_CLASS(CExtGridCellComboBox) )
  139. );
  140. pCellValidationFunction->ModifyStyle( __EGCS_NO_INPLACE_CONTROL );
  141. pCellValidationFunction->AddString( _T("(null)") );
  142. pCellValidationFunction->AddString( _T("IsNumeric") );
  143. pCellValidationFunction->AddString( _T("IsAlpha") );
  144. pCellValidationFunction->AddString( _T("IsAlphaOrNumeric") );
  145. if( strFunctionNameValidation != NULL )
  146. pCellValidationFunction->SelectString( strFunctionNameValidation );
  147. else
  148. pCellValidationFunction->SetCurSel( 0L );
  149. CExtGridCellComboBox * pCellConversionFunction =
  150. STATIC_DOWNCAST(
  151. CExtGridCellComboBox,
  152. GridCellGet( 3L, nRuleIndex, 0, 0, RUNTIME_CLASS(CExtGridCellComboBox) )
  153. );
  154. pCellConversionFunction->ModifyStyle( __EGCS_NO_INPLACE_CONTROL );
  155. pCellConversionFunction->AddString( _T("(null)") );
  156. pCellConversionFunction->AddString( _T("MakeUpper") );
  157. pCellConversionFunction->AddString( _T("MakeLower") );
  158. if( strFunctionNameConversion != NULL )
  159. pCellConversionFunction->SelectString( strFunctionNameConversion );
  160. else
  161. pCellConversionFunction->SetCurSel( 0L );
  162. CExtGridCellColor * pCellColor =
  163. STATIC_DOWNCAST(
  164. CExtGridCellColor,
  165. GridCellGet( 4L, nRuleIndex, 0, 0, RUNTIME_CLASS(CExtGridCellColor) )
  166. );
  167. pCellColor->ModifyStyle( __EGCS_NO_INPLACE_CONTROL );
  168. pCellColor->SetColor( _cr.m_clrSymbol, false );
  169. OnSwUpdateScrollBars();
  170. FocusSet( CPoint( 0L, nRuleIndex ) );
  171. OnRuleSetChanged();
  172. }
  173. void RuleRemove(
  174. LONG nRuleIndex = -1 // -1 - focused
  175. )
  176. {
  177. ASSERT_VALID( this );
  178. LONG nRowCount = RowCountGet();
  179. if( ! ( 0L <= nRuleIndex && nRuleIndex < nRowCount ) )
  180. {
  181. nRuleIndex = FocusGet().y;
  182. if( nRuleIndex < 0 )
  183. return;
  184. ASSERT( 0L <= nRuleIndex && nRuleIndex < nRowCount );
  185. }
  186. RowRemove( nRuleIndex );
  187. OnRuleSetChanged();
  188. }
  189. bool RuleGetAt(
  190. LONG nRuleIndex,
  191. CExtEditWithBehavior::CBehaviorMasked::CharRule & _cr
  192. )
  193. {
  194. LONG nRowCount = RowCountGet();
  195. if( ! ( 0L <= nRuleIndex && nRuleIndex < nRowCount ) )
  196. return false;
  197. CExtGridCellBool * pCellStatus =
  198. STATIC_DOWNCAST(
  199. CExtGridCellBool,
  200. GridCellGet( 0L, nRuleIndex )
  201. );
  202. if( ! pCellStatus->DataGet() )
  203. return false;
  204. CExtGridCellString * pCellOneCharacter =
  205. STATIC_DOWNCAST(
  206. CExtGridCellString,
  207. GridCellGet( 1L, nRuleIndex )
  208. );
  209. CExtSafeString strChr;
  210. pCellOneCharacter->TextGet( strChr );
  211. static __EXT_MFC_SAFE_LPCTSTR g_strTrimChars = _T(" rnt");
  212. strChr.TrimLeft( g_strTrimChars );
  213. strChr.TrimRight( g_strTrimChars );
  214. if( strChr.GetLength() != 1 )
  215. return false;
  216. _cr.Set( strChr.GetAt( 0 ) );
  217. CExtGridCellComboBox * pCellValidationFunction =
  218. STATIC_DOWNCAST(
  219. CExtGridCellComboBox,
  220. GridCellGet( 2L, nRuleIndex )
  221. );
  222. switch( pCellValidationFunction->GetCurSel() )
  223. {
  224. case 0: /* valid case, null function */ break;
  225. case 1: _cr.m_fnValidation = (CExtEditWithBehavior::CBehaviorMasked::CharRule::ValidationFunction)CExtEditMasked::stat_IsCharDigit; break;
  226. case 2: _cr.m_fnValidation = (CExtEditWithBehavior::CBehaviorMasked::CharRule::ValidationFunction)CExtEditMasked::stat_IsCharAlpha; break;
  227. case 3: _cr.m_fnValidation = (CExtEditWithBehavior::CBehaviorMasked::CharRule::ValidationFunction)CExtEditMasked::stat_IsCharAlphaOrDigit; break;
  228. #ifdef _DEBUG
  229. default:
  230. ASSERT( FALSE );
  231. break;
  232. #endif // _DEBUG
  233. }
  234. CExtGridCellComboBox * pCellConversionFunction =
  235. STATIC_DOWNCAST(
  236. CExtGridCellComboBox,
  237. GridCellGet( 3L, nRuleIndex )
  238. );
  239. switch( pCellConversionFunction->GetCurSel() )
  240. {
  241. case 0: /* valid case, null function */ break;
  242. case 1: _cr.m_fnConversion = (CExtEditWithBehavior::CBehaviorMasked::CharRule::ConversionFunction)_totupper; break;
  243. case 2: _cr.m_fnConversion = (CExtEditWithBehavior::CBehaviorMasked::CharRule::ConversionFunction)_totlower; break;
  244. #ifdef _DEBUG
  245. default:
  246. ASSERT( FALSE );
  247. break;
  248. #endif // _DEBUG
  249. }
  250. CExtGridCellColor * pCellColor =
  251. STATIC_DOWNCAST(
  252. CExtGridCellColor,
  253. GridCellGet( 4L, nRuleIndex )
  254. );
  255. _cr.m_clrSymbol = pCellColor->GetColor();
  256. return true;
  257. }
  258. void RuleResetAll()
  259. {
  260. RowRemoveAll( false );
  261. // default mask symbol number
  262. CExtEditWithBehavior::CBehaviorMasked::CharRule _rule1( RGB(164,0,0), _T('#'), (CExtEditWithBehavior::CBehaviorMasked::CharRule::ValidationFunction)CExtEditMasked::stat_IsCharDigit );
  263. RuleAdd( true, _rule1, _T("IsNumeric"), NULL );
  264. // default mask symbol letter
  265. CExtEditWithBehavior::CBehaviorMasked::CharRule _rule2( RGB(0,164,0), _T('@'), (CExtEditWithBehavior::CBehaviorMasked::CharRule::ValidationFunction)CExtEditMasked::stat_IsCharAlpha );
  266. RuleAdd( true, _rule2, _T("IsAlpha"), NULL );
  267. // default mask symbol number and letter
  268. CExtEditWithBehavior::CBehaviorMasked::CharRule _rule3( RGB(0,0,164), _T('$'), (CExtEditWithBehavior::CBehaviorMasked::CharRule::ValidationFunction)CExtEditMasked::stat_IsCharAlphaOrDigit );
  269. RuleAdd( true, _rule3, _T("IsAlphaOrNumeric"), NULL );
  270. }
  271. };
  272. CRuleGridWnd m_wndRuleGrid;
  273. //{{AFX_VIRTUAL(CPageMaskedEdit)
  274. protected:
  275. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  276. //}}AFX_VIRTUAL
  277. protected:
  278. bool m_bInitComplete:1;
  279. //{{AFX_MSG(CPageMaskedEdit)
  280. virtual BOOL OnInitDialog();
  281. afx_msg void OnUseMaskedRichEdit();
  282. afx_msg void OnCharRuleAdd();
  283. afx_msg void OnCharRuleRemove();
  284. afx_msg void OnChangeEditMask();
  285. afx_msg void OnCharRuleResetAll();
  286. afx_msg void OnOptionChanged();
  287. afx_msg void OnSetfocusEditNullChar();
  288. //}}AFX_MSG
  289. DECLARE_MESSAGE_MAP()
  290. };
  291. #endif // (!defined __EXT_MFC_NO_GRIDWND )
  292. /////////////////////////////////////////////////////////////////////////////
  293. // CPageSystemNumberCurrencyEditors dialog
  294. class CPageSystemNumberCurrencyEditors : public CPageBase 
  295. {
  296. protected:
  297. CList < UINT, UINT > m_listColorButtonIDs;
  298. public:
  299. // INT m_nTestNumberWholeDigits, m_nTestNumberFractionDigits;
  300. CPageSystemNumberCurrencyEditors(CWnd* pParent = NULL);   // standard constructor
  301. //{{AFX_DATA(CPageSystemNumberCurrencyEditors)
  302. enum { IDD = IDD_PAGE_SYSTEM_NUMBER_CURRENCY_EDITORS };
  303. CExtCheckBox m_checkUseRichEditors;
  304. CExtEditSystemNumber m_editSystemNumberSimple;
  305. CExtEditSystemNumber m_editSystemNumberRich;
  306. CExtLabel m_labelValueOfSystemNumberEditor;
  307. CExtEditSystemCurrency m_editSystemCurrencySimple;
  308. CExtEditSystemCurrency m_editSystemCurrencyRich;
  309. CExtLabel m_labelValueOfSystemCurrencyEditor;
  310. CExtEdit m_editMaxWholeDigits;
  311. CExtSpinWnd m_spinMaxWholeDigits;
  312. CExtEdit m_editMaxFractionDigits;
  313. CExtSpinWnd m_spinMaxFractionDigits;
  314. CExtCheckBox m_checkCanBeNegative;
  315. CExtColorButton m_buttonColorNumber;
  316. CExtColorButton m_buttonColorFraction;
  317. CExtColorButton m_buttonColorSign;
  318. CExtColorButton m_buttonColorBrackets;
  319. CExtColorButton m_buttonColorSeparatorGroup;
  320. CExtColorButton m_buttonColorSeparatorDecimal;
  321. CExtColorButton m_buttonDefaultText;
  322. CExtColorButton m_buttonDefaultBack;
  323. //}}AFX_DATA
  324. //{{AFX_VIRTUAL(CPageSystemNumberCurrencyEditors)
  325. protected:
  326. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  327. //}}AFX_VIRTUAL
  328. protected:
  329. bool m_bInitComplete:1;
  330. void _SyncFrom( CExtEditSystemNumberCurrencyBase * pWndEditSyncFrom );
  331. void _SyncValueOfNumber();
  332. void _SyncValueOfCurrency();
  333. //{{AFX_MSG(CPageSystemNumberCurrencyEditors)
  334. virtual BOOL OnInitDialog();
  335. afx_msg void OnCheckUseRichEditors();
  336. afx_msg void OnChangeEditSystemNumberSimple();
  337. afx_msg void OnChangeEditSystemNumberRich();
  338. afx_msg void OnChangeEditSystemCurrencySimple();
  339. afx_msg void OnChangeEditSystemCurrencyRich();
  340. afx_msg void OnChangeMaxWholeDigits();
  341. afx_msg void OnChangeMaxFractionDigits();
  342. afx_msg void OnCheckCanBeNegative();
  343. afx_msg void OnChangeWindowsLocaleSettings();
  344. //}}AFX_MSG
  345. afx_msg LRESULT OnColorChangedFinally( WPARAM wParam, LPARAM lParam );
  346. afx_msg LRESULT OnColorSelectCustom( WPARAM wParam, LPARAM lParam );
  347. DECLARE_MESSAGE_MAP()
  348. };
  349. #endif // ( ! defined __PAGE_MASKED_EDIT_H )
  350. //{{AFX_INSERT_LOCATION}}
  351. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.