OptionsTypes.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. m_csTitle = theApp.m_Language.GetString("SupportedTypesTitle", "Supported Types");
  18. m_psp.pszTitle = m_csTitle;
  19. m_psp.dwFlags |= PSP_USETITLE;
  20. //{{AFX_DATA_INIT(COptionsTypes)
  21. //}}AFX_DATA_INIT
  22. m_bSave = false;
  23. }
  24. COptionsTypes::~COptionsTypes()
  25. {
  26. }
  27. void COptionsTypes::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CPropertyPage::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(COptionsTypes)
  31. DDX_Control(pDX, IDC_LIST1, m_List);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(COptionsTypes, CPropertyPage)
  35. //{{AFX_MSG_MAP(COptionsTypes)
  36. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  37. ON_BN_CLICKED(IDC_ADD, OnAdd)
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // COptionsTypes message handlers
  42. BOOL COptionsTypes::OnApply()
  43. {
  44. if(m_bSave)
  45. {
  46. try
  47. {
  48. CTypesTable recset;
  49. recset.DeleteAll();
  50. recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM Types" ,NULL);
  51. int nCount = m_List.GetCount();
  52. for(int i = 0; i < nCount; i++)
  53. {
  54. recset.AddNew();
  55. m_List.GetText(i, recset.m_TypeText);
  56. recset.Update();
  57. }
  58. recset.Close();
  59. }
  60. CATCHDAO
  61. // refresh our local cache
  62. theApp.ReloadTypes();
  63. }
  64. return CPropertyPage::OnApply();
  65. }
  66. BOOL COptionsTypes::OnInitDialog()
  67. {
  68. CPropertyPage::OnInitDialog();
  69. try
  70. {
  71. CTypesTable recset;
  72. recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM Types" ,NULL);
  73. if(recset.IsEOF())
  74. {
  75. m_List.AddString("CF_TEXT");
  76. m_List.AddString(GetFormatName(RegisterClipboardFormat(CF_RTF)));
  77. m_List.AddString("CF_DIB");
  78. }
  79. while(!recset.IsEOF())
  80. {
  81. m_List.AddString(recset.m_TypeText);
  82. recset.MoveNext();
  83. }
  84. }
  85. CATCHDAO
  86. m_List.SetFocus();
  87. theApp.m_Language.UpdateOptionSupportedTypes(this);
  88. return FALSE;
  89. }
  90. void COptionsTypes::OnDelete()
  91. {
  92. int nCount = m_List.GetSelCount();
  93. if(nCount)
  94. {
  95. m_bSave = true;
  96. CArrayEx<int> items;
  97. items.SetSize(nCount);
  98. m_List.GetSelItems(nCount, items.GetData());
  99. items.SortDescending();
  100. for(int i = 0; i < nCount; i++)
  101. m_List.DeleteString(items[i]);
  102. }
  103. }
  104. #include "AddType.h"
  105. void COptionsTypes::OnAdd()
  106. {
  107. CAddType add(this);
  108. if(add.DoModal() == IDOK)
  109. {
  110. int nCount = add.m_csSelectedTypes.GetSize();
  111. if(nCount)
  112. {
  113. m_bSave = true;
  114. for(int i = 0; i < nCount; i++)
  115. {
  116. if(TextAllReadyThere(add.m_csSelectedTypes[i]) == FALSE)
  117. m_List.AddString(add.m_csSelectedTypes[i]);
  118. }
  119. }
  120. }
  121. }
  122. BOOL COptionsTypes::TextAllReadyThere(const CString &cs)
  123. {
  124. CString csThere;
  125. int nCount = m_List.GetCount();
  126. for(int i = 0; i < nCount; i++)
  127. {
  128. m_List.GetText(i, csThere);
  129. if(cs == csThere)
  130. return TRUE;
  131. }
  132. return FALSE;
  133. }