OptionsTypes.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. try
  44. {
  45. CTypesTable recset;
  46. recset.DeleteAll();
  47. recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM Types" ,NULL);
  48. int nCount = m_List.GetCount();
  49. for(int i = 0; i < nCount; i++)
  50. {
  51. recset.AddNew();
  52. m_List.GetText(i, recset.m_TypeText);
  53. recset.Update();
  54. }
  55. recset.Close();
  56. }
  57. CATCHDAO
  58. // refresh our local cache
  59. theApp.ReloadTypes();
  60. }
  61. return CPropertyPage::OnApply();
  62. }
  63. BOOL COptionsTypes::OnInitDialog()
  64. {
  65. CPropertyPage::OnInitDialog();
  66. try
  67. {
  68. CTypesTable recset;
  69. recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM Types" ,NULL);
  70. if(recset.IsEOF())
  71. {
  72. m_List.AddString("CF_TEXT");
  73. m_List.AddString(GetFormatName(RegisterClipboardFormat(CF_RTF)));
  74. m_List.AddString("CF_DIB");
  75. }
  76. while(!recset.IsEOF())
  77. {
  78. m_List.AddString(recset.m_TypeText);
  79. recset.MoveNext();
  80. }
  81. }
  82. CATCHDAO
  83. m_List.SetFocus();
  84. return FALSE;
  85. }
  86. void COptionsTypes::OnDelete()
  87. {
  88. int nCount = m_List.GetSelCount();
  89. if(nCount)
  90. {
  91. m_bSave = true;
  92. CArrayEx<int> items;
  93. items.SetSize(nCount);
  94. m_List.GetSelItems(nCount, items.GetData());
  95. items.SortDescending();
  96. for(int i = 0; i < nCount; i++)
  97. m_List.DeleteString(items[i]);
  98. }
  99. }
  100. #include "AddType.h"
  101. void COptionsTypes::OnAdd()
  102. {
  103. CAddType add(this);
  104. if(add.DoModal() == IDOK)
  105. {
  106. int nCount = add.m_csSelectedTypes.GetSize();
  107. if(nCount)
  108. {
  109. m_bSave = true;
  110. for(int i = 0; i < nCount; i++)
  111. {
  112. if(TextAllReadyThere(add.m_csSelectedTypes[i]) == FALSE)
  113. m_List.AddString(add.m_csSelectedTypes[i]);
  114. }
  115. }
  116. }
  117. }
  118. BOOL COptionsTypes::TextAllReadyThere(const CString &cs)
  119. {
  120. CString csThere;
  121. int nCount = m_List.GetCount();
  122. for(int i = 0; i < nCount; i++)
  123. {
  124. m_List.GetText(i, csThere);
  125. if(cs == csThere)
  126. return TRUE;
  127. }
  128. return FALSE;
  129. }