OptionsTypes.cpp 3.4 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. #include "DimWnd.h"
  8. #include "Misc.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // COptionsTypes property page
  16. IMPLEMENT_DYNCREATE(COptionsTypes, CPropertyPage)
  17. COptionsTypes::COptionsTypes() : CPropertyPage(COptionsTypes::IDD)
  18. {
  19. m_csTitle = theApp.m_Language.GetString("SupportedTypesTitle", "Supported Types");
  20. m_psp.pszTitle = m_csTitle;
  21. m_psp.dwFlags |= PSP_USETITLE;
  22. //{{AFX_DATA_INIT(COptionsTypes)
  23. //}}AFX_DATA_INIT
  24. m_bSave = false;
  25. }
  26. COptionsTypes::~COptionsTypes()
  27. {
  28. }
  29. void COptionsTypes::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CPropertyPage::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(COptionsTypes)
  33. DDX_Control(pDX, IDC_LIST1, m_List);
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(COptionsTypes, CPropertyPage)
  37. //{{AFX_MSG_MAP(COptionsTypes)
  38. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  39. ON_BN_CLICKED(IDC_ADD, OnAdd)
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // COptionsTypes message handlers
  44. BOOL COptionsTypes::OnApply()
  45. {
  46. if(m_bSave)
  47. {
  48. try
  49. {
  50. theApp.m_db.execDML(_T("DELETE FROM Types;"));
  51. CString csText;
  52. int nCount = m_List.GetCount();
  53. for(int i = 0; i < nCount; i++)
  54. {
  55. m_List.GetText(i, csText);
  56. theApp.m_db.execDMLEx(_T("INSERT INTO Types VALUES(NULL, '%s');"), csText);
  57. }
  58. }
  59. CATCH_SQLITE_EXCEPTION
  60. // refresh our local cache
  61. theApp.ReloadTypes();
  62. }
  63. return CPropertyPage::OnApply();
  64. }
  65. BOOL COptionsTypes::OnInitDialog()
  66. {
  67. CPropertyPage::OnInitDialog();
  68. try
  69. {
  70. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT TypeText FROM Types"));
  71. if(q.eof())
  72. {
  73. m_List.AddString(_T("CF_TEXT"));
  74. m_List.AddString(GetFormatName(RegisterClipboardFormat(CF_RTF)));
  75. m_List.AddString(_T("CF_UNICODETEXT"));
  76. m_List.AddString(_T("CF_HDROP"));
  77. m_List.AddString(_T("CF_DIB"));
  78. m_List.AddString(GetFormatName(GetFormatID(_T("HTML Format"))));
  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. CDimWnd dim(this->GetParent());
  109. CAddType add(this);
  110. if(add.DoModal() == IDOK)
  111. {
  112. INT_PTR nCount = add.m_csSelectedTypes.GetSize();
  113. if(nCount)
  114. {
  115. m_bSave = true;
  116. for(int i = 0; i < nCount; i++)
  117. {
  118. if(TextAllReadyThere(add.m_csSelectedTypes[i]) == FALSE)
  119. m_List.AddString(add.m_csSelectedTypes[i]);
  120. }
  121. }
  122. }
  123. }
  124. BOOL COptionsTypes::TextAllReadyThere(const CString &cs)
  125. {
  126. CString csThere;
  127. int nCount = m_List.GetCount();
  128. for(int i = 0; i < nCount; i++)
  129. {
  130. m_List.GetText(i, csThere);
  131. if(cs == csThere)
  132. return TRUE;
  133. }
  134. return FALSE;
  135. }