-
-
Notifications
You must be signed in to change notification settings - Fork 208
/
AddType.cpp
167 lines (136 loc) · 4 KB
/
AddType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// AddType.cpp : implementation file
//
#include "stdafx.h"
#include "cp_main.h"
#include "Misc.h"
#include "AddType.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAddType dialog
CAddType::CAddType(CWnd* pParent /*=NULL*/)
: CDialog(CAddType::IDD, pParent)
{
//{{AFX_DATA_INIT(CAddType)
m_eCustomType = _T("");
//}}AFX_DATA_INIT
}
void CAddType::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddType)
DDX_Control(pDX, IDC_LIST1, m_lbCandidateTypes);
DDX_Text(pDX, IDC_EDIT1, m_eCustomType);
DDV_MaxChars(pDX, m_eCustomType, 50);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddType, CDialog)
//{{AFX_MSG_MAP(CAddType)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_RADIO_PRIMARY_TYPES, &CAddType::OnBnClickedRadioPrimaryTypes)
ON_BN_CLICKED(IDC_RADIO_CURRENT_TYPES, &CAddType::OnBnClickedRadioCurrentTypes)
ON_BN_CLICKED(IDC_RADIO_CUSTOM_TYPE, &CAddType::OnBnClickedRadioCustomType)
ON_BN_CLICKED(IDC_ADD_3, &CAddType::OnBnClickedAdd)
ON_LBN_DBLCLK(IDC_LIST1, &CAddType::OnLbnDblclkList)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAddType message handlers
BOOL CAddType::OnInitDialog()
{
CDialog::OnInitDialog();
::CheckDlgButton(m_hWnd, IDC_RADIO_CURRENT_TYPES, BST_CHECKED);
OnBnClickedRadioCurrentTypes();
m_lbCandidateTypes.SetFocus();
theApp.m_Language.UpdateOptionSupportedTypesAdd(this);
return FALSE;
}
void CAddType::AddCurrentClipboardTypes()
{
m_lbCandidateTypes.ResetContent();
COleDataObject oleData;
if (!oleData.AttachClipboard())
return;
oleData.BeginEnumFormats();
FORMATETC test;
while (oleData.GetNextFormat(&test))
{
BOOL b = oleData.IsDataAvailable(test.cfFormat);
m_lbCandidateTypes.AddString(GetFormatName(test.cfFormat));
}
oleData.Release();
}
void CAddType::AddCommonTypes()
{
m_lbCandidateTypes.ResetContent();
for (auto systemClipFormat : GetSystemClipFormats()) {
m_lbCandidateTypes.AddString(GetFormatName(systemClipFormat));
}
m_lbCandidateTypes.AddString(GetFormatName(RegisterClipboardFormat(CF_RTF)));
m_lbCandidateTypes.AddString(GetFormatName(RegisterClipboardFormat(CF_RTFNOOBJS)));
m_lbCandidateTypes.AddString(GetFormatName(RegisterClipboardFormat(CF_RETEXTOBJ)));
m_lbCandidateTypes.AddString(GetFormatName(RegisterClipboardFormat(_T("HTML Format"))));
}
void CAddType::OnBnClickedRadioPrimaryTypes()
{
AddCommonTypes();
::ShowWindow(::GetDlgItem(m_hWnd, IDC_LIST1), SW_SHOW);
::ShowWindow(::GetDlgItem(m_hWnd, IDC_EDIT1), SW_HIDE);
m_lbCandidateTypes.SetFocus();
if (m_lbCandidateTypes.GetCount() > 0)
{
m_lbCandidateTypes.SetCurSel(0);
m_lbCandidateTypes.SetSel(0);
}
}
void CAddType::OnBnClickedRadioCurrentTypes()
{
AddCurrentClipboardTypes();
::ShowWindow(::GetDlgItem(m_hWnd, IDC_LIST1), SW_SHOW);
::ShowWindow(::GetDlgItem(m_hWnd, IDC_EDIT1), SW_HIDE);
m_lbCandidateTypes.SetFocus();
if (m_lbCandidateTypes.GetCount() > 0)
{
m_lbCandidateTypes.SetCurSel(0);
m_lbCandidateTypes.SetSel(0);
}
}
void CAddType::OnBnClickedRadioCustomType()
{
::ShowWindow(::GetDlgItem(m_hWnd, IDC_EDIT1), SW_SHOW);
::ShowWindow(::GetDlgItem(m_hWnd, IDC_LIST1), SW_HIDE);
::SetFocus(::GetDlgItem(m_hWnd, IDC_EDIT1));
}
void CAddType::OnBnClickedAdd()
{
m_csSelectedTypes.RemoveAll();
if (IsDlgButtonChecked(IDC_RADIO_PRIMARY_TYPES) == BST_CHECKED ||
IsDlgButtonChecked(IDC_RADIO_CURRENT_TYPES) == BST_CHECKED)
{
int nCount = m_lbCandidateTypes.GetSelCount();
if (nCount)
{
CString cs;
CArray<int, int> items;
items.SetSize(nCount);
m_lbCandidateTypes.GetSelItems(nCount, items.GetData());
for (int i = 0; i < nCount; i++)
{
m_lbCandidateTypes.GetText(items[i], cs);
m_csSelectedTypes.Add(cs);
}
}
}
else if (IsDlgButtonChecked(IDC_RADIO_CUSTOM_TYPE) == BST_CHECKED)
{
UpdateData();
m_csSelectedTypes.Add(m_eCustomType);
}
EndDialog(IDOK);
}
void CAddType::OnLbnDblclkList()
{
OnBnClickedAdd();
}