| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- // OptionsTypes.cpp : implementation file
- //
- #include "stdafx.h"
- #include "CP_Main.h"
- #include "OptionsTypes.h"
- #include "ArrayEx.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // COptionsTypes property page
- IMPLEMENT_DYNCREATE(COptionsTypes, CPropertyPage)
- COptionsTypes::COptionsTypes() : CPropertyPage(COptionsTypes::IDD)
- {
- //{{AFX_DATA_INIT(COptionsTypes)
- //}}AFX_DATA_INIT
- m_bSave = false;
- }
- COptionsTypes::~COptionsTypes()
- {
- }
- void COptionsTypes::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(COptionsTypes)
- DDX_Control(pDX, IDC_LIST1, m_List);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(COptionsTypes, CPropertyPage)
- //{{AFX_MSG_MAP(COptionsTypes)
- ON_BN_CLICKED(IDC_DELETE, OnDelete)
- ON_BN_CLICKED(IDC_ADD, OnAdd)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // COptionsTypes message handlers
- BOOL COptionsTypes::OnApply()
- {
- if(m_bSave)
- {
- CTypesTable recset;
- recset.DeleteAll();
- recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM Types" ,NULL);
- int nCount = m_List.GetCount();
- for(int i = 0; i < nCount; i++)
- {
- recset.AddNew();
- m_List.GetText(i, recset.m_TypeText);
- recset.Update();
- }
- recset.Close();
- // refresh our local cache
- theApp.ReloadTypes();
- }
-
- return CPropertyPage::OnApply();
- }
- BOOL COptionsTypes::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
-
- CTypesTable recset;
- recset.Open(AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM Types" ,NULL);
- if(recset.IsEOF())
- {
- m_List.AddString("CF_TEXT");
- m_List.AddString(GetFormatName(RegisterClipboardFormat(CF_RTF)));
- }
- while(!recset.IsEOF())
- {
- m_List.AddString(recset.m_TypeText);
- recset.MoveNext();
- }
-
- m_List.SetFocus();
- return FALSE;
- }
- void COptionsTypes::OnDelete()
- {
- int nCount = m_List.GetSelCount();
- if(nCount)
- {
- m_bSave = true;
- CArrayEx<int> items;
- items.SetSize(nCount);
- m_List.GetSelItems(nCount, items.GetData());
- items.SortDescending();
- for(int i = 0; i < nCount; i++)
- m_List.DeleteString(items[i]);
- }
- }
- #include "AddType.h"
- void COptionsTypes::OnAdd()
- {
- CAddType add(this);
- if(add.DoModal() == IDOK)
- {
- int nCount = add.m_csSelectedTypes.GetSize();
- if(nCount)
- {
- m_bSave = true;
- for(int i = 0; i < nCount; i++)
- {
- if(TextAllReadyThere(add.m_csSelectedTypes[i]) == FALSE)
- m_List.AddString(add.m_csSelectedTypes[i]);
- }
- }
- }
- }
- BOOL COptionsTypes::TextAllReadyThere(const CString &cs)
- {
- CString csThere;
- int nCount = m_List.GetCount();
- for(int i = 0; i < nCount; i++)
- {
- m_List.GetText(i, csThere);
- if(cs == csThere)
- return TRUE;
- }
- return FALSE;
- }
|