OptionsTypes.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // OptionsTypes.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "OptionsTypes.h"
  6. #include "ArrayEx.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // COptionsTypes property page
  14. IMPLEMENT_DYNCREATE(COptionsTypes, CPropertyPage)
  15. COptionsTypes::COptionsTypes() : CPropertyPage(COptionsTypes::IDD)
  16. {
  17. //{{AFX_DATA_INIT(COptionsTypes)
  18. //}}AFX_DATA_INIT
  19. m_bSave = false;
  20. }
  21. COptionsTypes::~COptionsTypes()
  22. {
  23. }
  24. void COptionsTypes::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CPropertyPage::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(COptionsTypes)
  28. DDX_Control(pDX, IDC_LIST1, m_List);
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(COptionsTypes, CPropertyPage)
  32. //{{AFX_MSG_MAP(COptionsTypes)
  33. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  34. ON_BN_CLICKED(IDC_ADD, OnAdd)
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // COptionsTypes message handlers
  39. BOOL COptionsTypes::OnApply()
  40. {
  41. if(m_bSave)
  42. {
  43. CTypesTable recset;
  44. recset.DeleteAll();
  45. recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM Types" ,NULL);
  46. int nCount = m_List.GetCount();
  47. for(int i = 0; i < nCount; i++)
  48. {
  49. recset.AddNew();
  50. m_List.GetText(i, recset.m_TypeText);
  51. recset.Update();
  52. }
  53. recset.Close();
  54. // refresh our local cache
  55. theApp.ReloadTypes();
  56. }
  57. return CPropertyPage::OnApply();
  58. }
  59. BOOL COptionsTypes::OnInitDialog()
  60. {
  61. CPropertyPage::OnInitDialog();
  62. CTypesTable recset;
  63. recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM Types" ,NULL);
  64. if(recset.IsEOF())
  65. {
  66. m_List.AddString("CF_TEXT");
  67. m_List.AddString(GetFormatName(RegisterClipboardFormat(CF_RTF)));
  68. }
  69. while(!recset.IsEOF())
  70. {
  71. m_List.AddString(recset.m_TypeText);
  72. recset.MoveNext();
  73. }
  74. m_List.SetFocus();
  75. return FALSE;
  76. }
  77. void COptionsTypes::OnDelete()
  78. {
  79. int nCount = m_List.GetSelCount();
  80. if(nCount)
  81. {
  82. m_bSave = true;
  83. CArrayEx<int> items;
  84. items.SetSize(nCount);
  85. m_List.GetSelItems(nCount, items.GetData());
  86. items.SortDescending();
  87. for(int i = 0; i < nCount; i++)
  88. m_List.DeleteString(items[i]);
  89. }
  90. }
  91. #include "AddType.h"
  92. void COptionsTypes::OnAdd()
  93. {
  94. CAddType add(this);
  95. if(add.DoModal() == IDOK)
  96. {
  97. int nCount = add.m_csSelectedTypes.GetSize();
  98. if(nCount)
  99. {
  100. m_bSave = true;
  101. for(int i = 0; i < nCount; i++)
  102. {
  103. if(TextAllReadyThere(add.m_csSelectedTypes[i]) == FALSE)
  104. m_List.AddString(add.m_csSelectedTypes[i]);
  105. }
  106. }
  107. }
  108. }
  109. BOOL COptionsTypes::TextAllReadyThere(const CString &cs)
  110. {
  111. CString csThere;
  112. int nCount = m_List.GetCount();
  113. for(int i = 0; i < nCount; i++)
  114. {
  115. m_List.GetText(i, csThere);
  116. if(cs == csThere)
  117. return TRUE;
  118. }
  119. return FALSE;
  120. }