OptionsTypes.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. if(g_Opt.m_bU3 == false)
  76. {
  77. m_List.AddString(_T("CF_DIB"));
  78. }
  79. }
  80. while(q.eof() == false)
  81. {
  82. m_List.AddString(q.getStringField(0));
  83. q.nextRow();
  84. }
  85. }
  86. CATCH_SQLITE_EXCEPTION
  87. m_List.SetFocus();
  88. theApp.m_Language.UpdateOptionSupportedTypes(this);
  89. return FALSE;
  90. }
  91. void COptionsTypes::OnDelete()
  92. {
  93. int nCount = m_List.GetSelCount();
  94. if(nCount)
  95. {
  96. m_bSave = true;
  97. CArrayEx<int> items;
  98. items.SetSize(nCount);
  99. m_List.GetSelItems(nCount, items.GetData());
  100. items.SortDescending();
  101. for(int i = 0; i < nCount; i++)
  102. m_List.DeleteString(items[i]);
  103. }
  104. }
  105. #include "AddType.h"
  106. void COptionsTypes::OnAdd()
  107. {
  108. CAddType add(this);
  109. if(add.DoModal() == IDOK)
  110. {
  111. INT_PTR nCount = add.m_csSelectedTypes.GetSize();
  112. if(nCount)
  113. {
  114. m_bSave = true;
  115. for(int i = 0; i < nCount; i++)
  116. {
  117. if(TextAllReadyThere(add.m_csSelectedTypes[i]) == FALSE)
  118. m_List.AddString(add.m_csSelectedTypes[i]);
  119. }
  120. }
  121. }
  122. }
  123. BOOL COptionsTypes::TextAllReadyThere(const CString &cs)
  124. {
  125. CString csThere;
  126. int nCount = m_List.GetCount();
  127. for(int i = 0; i < nCount; i++)
  128. {
  129. m_List.GetText(i, csThere);
  130. if(cs == csThere)
  131. return TRUE;
  132. }
  133. return FALSE;
  134. }