OptionsTypes.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // COptionsTypes property page
  15. IMPLEMENT_DYNCREATE(COptionsTypes, CPropertyPage)
  16. COptionsTypes::COptionsTypes() : CPropertyPage(COptionsTypes::IDD)
  17. {
  18. m_csTitle = theApp.m_Language.GetString("SupportedTypesTitle", "Supported Types");
  19. m_psp.pszTitle = m_csTitle;
  20. m_psp.dwFlags |= PSP_USETITLE;
  21. //{{AFX_DATA_INIT(COptionsTypes)
  22. //}}AFX_DATA_INIT
  23. m_bSave = false;
  24. }
  25. COptionsTypes::~COptionsTypes()
  26. {
  27. }
  28. void COptionsTypes::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CPropertyPage::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(COptionsTypes)
  32. DDX_Control(pDX, IDC_LIST1, m_List);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(COptionsTypes, CPropertyPage)
  36. //{{AFX_MSG_MAP(COptionsTypes)
  37. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  38. ON_BN_CLICKED(IDC_ADD, OnAdd)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // COptionsTypes message handlers
  43. BOOL COptionsTypes::OnApply()
  44. {
  45. if(m_bSave)
  46. {
  47. try
  48. {
  49. theApp.m_db.execDML(_T("DELETE FROM Types;"));
  50. CString csText;
  51. int nCount = m_List.GetCount();
  52. for(int i = 0; i < nCount; i++)
  53. {
  54. m_List.GetText(i, csText);
  55. theApp.m_db.execDMLEx(_T("INSERT INTO Types VALUES(NULL, '%s');"), csText);
  56. }
  57. }
  58. CATCH_SQLITE_EXCEPTION
  59. // refresh our local cache
  60. theApp.ReloadTypes();
  61. }
  62. return CPropertyPage::OnApply();
  63. }
  64. BOOL COptionsTypes::OnInitDialog()
  65. {
  66. CPropertyPage::OnInitDialog();
  67. try
  68. {
  69. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT TypeText FROM Types"));
  70. if(q.eof())
  71. {
  72. m_List.AddString(_T("CF_TEXT"));
  73. m_List.AddString(GetFormatName(RegisterClipboardFormat(CF_RTF)));
  74. m_List.AddString(_T("CF_UNICODETEXT"));
  75. m_List.AddString(_T("CF_HDROP"));
  76. m_List.AddString(_T("CF_DIB"));
  77. }
  78. while(q.eof() == false)
  79. {
  80. m_List.AddString(q.getStringField(0));
  81. q.nextRow();
  82. }
  83. }
  84. CATCH_SQLITE_EXCEPTION
  85. m_List.SetFocus();
  86. theApp.m_Language.UpdateOptionSupportedTypes(this);
  87. return FALSE;
  88. }
  89. void COptionsTypes::OnDelete()
  90. {
  91. int nCount = m_List.GetSelCount();
  92. if(nCount)
  93. {
  94. m_bSave = true;
  95. CArrayEx<int> items;
  96. items.SetSize(nCount);
  97. m_List.GetSelItems(nCount, items.GetData());
  98. items.SortDescending();
  99. for(int i = 0; i < nCount; i++)
  100. m_List.DeleteString(items[i]);
  101. }
  102. }
  103. #include "AddType.h"
  104. void COptionsTypes::OnAdd()
  105. {
  106. CDimWnd dim(this->GetParent());
  107. CAddType add(this);
  108. if(add.DoModal() == IDOK)
  109. {
  110. INT_PTR 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. }