OptionsTypes.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // OptionsTypes.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "OptionsTypes.h"
  6. #include "Shared/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. theApp.m_db.execDML(_T("DELETE FROM Types;"));
  49. CString csText;
  50. int nCount = m_List.GetCount();
  51. for(int i = 0; i < nCount; i++)
  52. {
  53. m_List.GetText(i, csText);
  54. theApp.m_db.execDMLEx(_T("INSERT INTO Types VALUES(NULL, '%s');"), csText);
  55. }
  56. }
  57. CATCH_SQLITE_EXCEPTION
  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. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT TypeText FROM Types"));
  69. if(q.eof())
  70. {
  71. m_List.AddString(_T("CF_TEXT"));
  72. m_List.AddString(GetFormatName(RegisterClipboardFormat(CF_RTF)));
  73. m_List.AddString(_T("CF_UNICODETEXT"));
  74. m_List.AddString(_T("CF_HDROP"));
  75. m_List.AddString(_T("CF_DIB"));
  76. }
  77. while(q.eof() == false)
  78. {
  79. m_List.AddString(q.getStringField(0));
  80. q.nextRow();
  81. }
  82. }
  83. CATCH_SQLITE_EXCEPTION
  84. m_List.SetFocus();
  85. theApp.m_Language.UpdateOptionSupportedTypes(this);
  86. return FALSE;
  87. }
  88. void COptionsTypes::OnDelete()
  89. {
  90. int nCount = m_List.GetSelCount();
  91. if(nCount)
  92. {
  93. m_bSave = true;
  94. CArrayEx<int> items;
  95. items.SetSize(nCount);
  96. m_List.GetSelItems(nCount, items.GetData());
  97. items.SortDescending();
  98. for(int i = 0; i < nCount; i++)
  99. m_List.DeleteString(items[i]);
  100. }
  101. }
  102. #include "AddType.h"
  103. void COptionsTypes::OnAdd()
  104. {
  105. CAddType add(this);
  106. if(add.DoModal() == IDOK)
  107. {
  108. INT_PTR nCount = add.m_csSelectedTypes.GetSize();
  109. if(nCount)
  110. {
  111. m_bSave = true;
  112. for(int i = 0; i < nCount; i++)
  113. {
  114. if(TextAllReadyThere(add.m_csSelectedTypes[i]) == FALSE)
  115. m_List.AddString(add.m_csSelectedTypes[i]);
  116. }
  117. }
  118. }
  119. }
  120. BOOL COptionsTypes::TextAllReadyThere(const CString &cs)
  121. {
  122. CString csThere;
  123. int nCount = m_List.GetCount();
  124. for(int i = 0; i < nCount; i++)
  125. {
  126. m_List.GetText(i, csThere);
  127. if(cs == csThere)
  128. return TRUE;
  129. }
  130. return FALSE;
  131. }