forked from irwir/eMule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListViewWalkerPropertySheet.cpp
283 lines (244 loc) · 7.34 KB
/
ListViewWalkerPropertySheet.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
//this file is part of eMule
//Copyright (C)2002-2010 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "stdafx.h"
#include "emule.h"
#include "ListViewWalkerPropertySheet.h"
#include "UserMsgs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define IDC_PREV 100
#define IDC_NEXT 101
// CListViewPropertySheet
IMPLEMENT_DYNAMIC(CListViewPropertySheet, CResizableSheet)
BEGIN_MESSAGE_MAP(CListViewPropertySheet, CResizableSheet)
END_MESSAGE_MAP()
CListViewPropertySheet::CListViewPropertySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CResizableSheet(nIDCaption, pParentWnd, iSelectPage)
{
}
CListViewPropertySheet::CListViewPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CResizableSheet(pszCaption, pParentWnd, iSelectPage)
{
}
CListViewPropertySheet::~CListViewPropertySheet()
{
}
void CListViewPropertySheet::InsertPage(int iIndex, CPropertyPage* pPage)
{
ASSERT_VALID( this );
ASSERT( pPage != NULL );
ASSERT_KINDOF( CPropertyPage, pPage );
ASSERT_VALID( pPage );
m_pages.InsertAt(iIndex, pPage);
BuildPropPageArray();
if (m_hWnd != NULL)
{
PROPSHEETPAGE* ppsp = const_cast<PROPSHEETPAGE*>(m_psh.ppsp);
for (UINT i = 0; i < m_psh.nPages; i++) {
if (i == (UINT)iIndex)
break;
(BYTE*&)ppsp += ppsp->dwSize;
}
HPROPSHEETPAGE hPSP = CreatePropertySheetPage(ppsp);
if (hPSP == NULL)
AfxThrowMemoryException();
if (!SendMessage(PSM_INSERTPAGE, iIndex, (LPARAM)hPSP)) {
DestroyPropertySheetPage(hPSP);
AfxThrowMemoryException();
}
}
}
void CListViewPropertySheet::ChangedData()
{
SendMessage(UM_DATA_CHANGED);
for (int iPage = 0; iPage < GetPageCount(); iPage++)
{
CPropertyPage* pPage = GetPage(iPage);
if (pPage && pPage->m_hWnd)
{
pPage->SendMessage(UM_DATA_CHANGED);
pPage->SetModified(FALSE);
}
}
GetActivePage()->OnSetActive();
}
// CListViewWalkerPropertySheet
IMPLEMENT_DYNAMIC(CListViewWalkerPropertySheet, CListViewPropertySheet)
BEGIN_MESSAGE_MAP(CListViewWalkerPropertySheet, CListViewPropertySheet)
ON_BN_CLICKED(IDC_NEXT, OnNext)
ON_BN_CLICKED(IDC_PREV, OnPrev)
END_MESSAGE_MAP()
CListViewWalkerPropertySheet::CListViewWalkerPropertySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CListViewPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
}
CListViewWalkerPropertySheet::CListViewWalkerPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CListViewPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
}
CListViewWalkerPropertySheet::~CListViewWalkerPropertySheet()
{
}
BOOL CListViewWalkerPropertySheet::OnInitDialog()
{
BOOL bResult = CListViewPropertySheet::OnInitDialog();
//////////////////////////////////////////////////////////////////////////
// Add additional controls
//
if (m_pListCtrl != NULL)
{
// switching from multi-selection to single selection is currently not supported -> disable Up/Down controls
DWORD dwCtrlStyle = (m_aItems.GetSize()>1) ? WS_DISABLED : 0;
const struct
{
CButton *pCtlBtn;
UINT uCtlId;
LPCTSTR pszLabel;
LPCTSTR pszSymbol;
DWORD dwStyle;
} aCtrls[] =
{
{ &m_ctlPrev, IDC_PREV, _T("&Prev"), _T("5"), WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP },
{ &m_ctlNext, IDC_NEXT, _T("&Next"), _T("6"), WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP }
};
int iLeftMostButtonId = IDOK;
int iMax = 32767;
static const int _aiPropSheetButtons[] = { IDOK, IDCANCEL, ID_APPLY_NOW, IDHELP };
for (int i = 0; i < ARRSIZE(_aiPropSheetButtons); i++)
{
CWnd* pBtn = GetDlgItem(_aiPropSheetButtons[i]);
if (pBtn /*&& pBtn->IsWindowVisible()*/)
{
CRect rcBtn;
pBtn->GetWindowRect(&rcBtn);
ScreenToClient(&rcBtn);
if (rcBtn.left < iMax)
{
iMax = rcBtn.left;
iLeftMostButtonId = _aiPropSheetButtons[i];
}
}
}
CWnd* pctlOk = GetDlgItem(iLeftMostButtonId);
CRect rcOk;
pctlOk->GetWindowRect(&rcOk);
ScreenToClient(&rcOk);
CFont* pDefCtrlFont = pctlOk->GetFont();
for (int i = 0; i < ARRSIZE(aCtrls); i++)
{
const int iNaviBtnWidth = rcOk.Width()/2;
CRect rc;
rc.left = rcOk.left - (8 + iNaviBtnWidth) * (ARRSIZE(aCtrls) - i);
rc.top = rcOk.top;
rc.right = rc.left + iNaviBtnWidth;
rc.bottom = rc.top + rcOk.Height();
VERIFY( aCtrls[i].pCtlBtn->Create(aCtrls[i].pszLabel, dwCtrlStyle | aCtrls[i].dwStyle, rc, this, aCtrls[i].uCtlId) );
if (theApp.m_fontSymbol.m_hObject)
{
aCtrls[i].pCtlBtn->SetFont(&theApp.m_fontSymbol);
aCtrls[i].pCtlBtn->SetWindowText(aCtrls[i].pszSymbol); // show down-arrow
}
else
aCtrls[i].pCtlBtn->SetFont(pDefCtrlFont);
AddAnchor(*aCtrls[i].pCtlBtn, BOTTOM_RIGHT);
}
}
return bResult;
}
void CListViewWalkerPropertySheet::OnPrev()
{
ASSERT( m_pListCtrl != NULL );
if (m_pListCtrl == NULL)
return;
CObject* pObj = m_pListCtrl->GetPrevSelectableItem();
if (pObj)
{
m_aItems.RemoveAll();
m_aItems.Add(pObj);
ChangedData();
}
else
MessageBeep(MB_OK);
}
void CListViewWalkerPropertySheet::OnNext()
{
ASSERT( m_pListCtrl != NULL );
if (m_pListCtrl == NULL)
return;
CObject* pObj = m_pListCtrl->GetNextSelectableItem();
if (pObj)
{
m_aItems.RemoveAll();
m_aItems.Add(pObj);
ChangedData();
}
else
MessageBeep(MB_OK);
}
CObject* CListCtrlItemWalk::GetPrevSelectableItem()
{
ASSERT( m_pListCtrl != NULL );
if (m_pListCtrl == NULL)
return NULL;
int iItemCount = m_pListCtrl->GetItemCount();
if (iItemCount >= 2)
{
POSITION pos = m_pListCtrl->GetFirstSelectedItemPosition();
if (pos)
{
int iItem = m_pListCtrl->GetNextSelectedItem(pos);
if (iItem-1 >= 0)
{
m_pListCtrl->SetItemState(iItem, 0, LVIS_SELECTED | LVIS_FOCUSED);
iItem--;
m_pListCtrl->SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
m_pListCtrl->SetSelectionMark(iItem);
m_pListCtrl->EnsureVisible(iItem, FALSE);
return STATIC_DOWNCAST(CObject, (CObject*)m_pListCtrl->GetItemData(iItem));
}
}
}
return NULL;
}
CObject* CListCtrlItemWalk::GetNextSelectableItem()
{
ASSERT( m_pListCtrl != NULL );
if (m_pListCtrl == NULL)
return NULL;
int iItemCount = m_pListCtrl->GetItemCount();
if (iItemCount >= 2)
{
POSITION pos = m_pListCtrl->GetFirstSelectedItemPosition();
if (pos)
{
int iItem = m_pListCtrl->GetNextSelectedItem(pos);
if (iItem+1 < iItemCount)
{
m_pListCtrl->SetItemState(iItem, 0, LVIS_SELECTED | LVIS_FOCUSED);
iItem++;
m_pListCtrl->SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
m_pListCtrl->SetSelectionMark(iItem);
m_pListCtrl->EnsureVisible(iItem, FALSE);
return STATIC_DOWNCAST(CObject, (CObject*)m_pListCtrl->GetItemData(iItem));
}
}
}
return NULL;
}