-
Notifications
You must be signed in to change notification settings - Fork 2
/
MarksList.cpp
347 lines (289 loc) · 8.85 KB
/
MarksList.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*
This file is part of Tibia Map Viewer.
Copyright (c) 2001-2006 by Yury Sidorov.
Tibia Map Viewer 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.
Tibia Map Viewer 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 Tibia Map Viewer; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// MarksList.cpp : implementation file
//
#include "stdafx.h"
#include "TMViewer.h"
#include "MarksList.h"
#include "EditMarkCat.h"
#include "Content.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMarksList dialog
CMarksList::CMarksList(CWnd* pParent /*=NULL*/)
: CDialog(CMarksList::IDD, pParent)
{
//{{AFX_DATA_INIT(CMarksList)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CMarksList::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMarksList)
DDX_Control(pDX, IDC_Marks, m_Marks);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMarksList, CDialog)
//{{AFX_MSG_MAP(CMarksList)
ON_BN_CLICKED(IDC_btNewMark, OnbtNewMark)
ON_BN_CLICKED(IDC_btEditMark, OnbtEditMark)
ON_BN_CLICKED(IDC_btDeleteMark, OnbtDeleteMark)
ON_WM_CLOSE()
ON_WM_DESTROY()
ON_NOTIFY(NM_CLICK, IDC_Marks, OnClickMarks)
ON_NOTIFY(NM_DBLCLK, IDC_Marks, OnDblclkMarks)
ON_NOTIFY(NM_RCLICK, IDC_Marks, OnRclickMarks)
ON_NOTIFY(NM_RDBLCLK, IDC_Marks, OnRdblclkMarks)
ON_BN_CLICKED(IDC_MoveUp, OnMoveUp)
ON_BN_CLICKED(IDC_MoveDown, OnMoveDown)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_Marks, OnItemchangedMarks)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMarksList message handlers
void CMarksList::OnbtNewMark()
{
CEditMarkCat d(this);
if (d.DoModal() == IDOK) {
CMarkCategory *mc = new CMarkCategory;
int idx;// = m_Marks.GetSelectionMark();
theApp.m_map.Content.MarkImages.Add(d.m_icon);
mc->Name = d.m_Name;
idx = theApp.m_map.Content.MarkCategories.Add(mc);
m_Marks.InsertItem(idx, d.m_Name, idx);
theApp.m_map.Content.Modified = TRUE;
UpdateButtons();
g_pMainFrame->CreateMarksTB();
}
}
BOOL CMarksList::OnInitDialog()
{
CDialog::OnInitDialog();
m_Images.Create(&theApp.m_map.Content.MarkImages);
m_Marks.SetImageList(&m_Images, LVSIL_SMALL);
CRect r;
m_Marks.GetClientRect(r);
m_Marks.InsertColumn(0, "", LVCFMT_LEFT, r.Width() - GetSystemMetrics(SM_CYVSCROLL));
m_Marks.SetExtendedStyle(m_Marks.GetExtendedStyle() | LVS_EX_FULLROWSELECT);
FillList();
UpdateButtons();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMarksList::OnbtEditMark()
{
CEditMarkCat d(this);
int idx = m_Marks.GetSelectionMark();
CMarkCategory *mc;
d.m_icon = theApp.m_map.Content.MarkImages.ExtractIcon(idx);
mc = theApp.m_map.Content.MarkCategories[idx];
d.m_Name = mc->Name;
d.m_Caption = "Edit marks category";
if (d.DoModal() == IDOK) {
theApp.m_map.Content.MarkImages.Replace(idx, d.m_icon);
mc->Name = d.m_Name;
m_Marks.SetItem(idx, 0, LVIF_TEXT, d.m_Name, idx, 0, 0, 0);
m_Marks.Update(idx);
theApp.m_map.Content.Modified = TRUE;
CContentObjects& objs = theApp.m_map.Content.Objects;
CContentObj *o;
for (int i = 0; i < objs.GetSize(); i++) {
o = objs[i];
if (o->GetType() == otMark && ((CContentMark*)o)->Category == idx)
g_pMainFrame->m_wndView.InvalidateObj(o);
}
UpdateButtons();
g_pMainFrame->CreateMarksTB();
}
}
void CMarksList::OnbtDeleteMark()
{
CMarkCategories &mcs = theApp.m_map.Content.MarkCategories;
int idx = m_Marks.GetSelectionMark();
CString s;
s.Format("Do you want to delete mark category '%s' ?", mcs[idx]->Name);
if (AfxMessageBox(s, MB_ICONQUESTION | MB_YESNO, 0) != IDYES) return;
BOOL del;
if (mcs.GetSize() > 1)
del = (AfxMessageBox("Delete all objects of this category ?", MB_ICONQUESTION | MB_YESNO, 0) == IDYES);
else
del = TRUE;
CContentObjects& objs = theApp.m_map.Content.Objects;
CContentObj *o;
int i = 0;
while (i < objs.GetSize()) {
o = objs[i];
if (o->GetType() == otMark && ((CContentMark*)o)->Category == idx) {
g_pMainFrame->m_wndView.InvalidateObj(o);
if (del)
objs.RemoveAt(i);
else {
((CContentMark*)o)->Category = 0;
i++;
}
}
else {
if (((CContentMark*)o)->Category > idx)
((CContentMark*)o)->Category--;
i++;
}
}
mcs.RemoveAt(idx);
m_Marks.DeleteItem(idx);
theApp.m_map.Content.MarkImages.Remove(idx);
theApp.m_map.Content.Modified = TRUE;
LVITEM it;
it.mask = LVIF_IMAGE;
for (i = 0; i < m_Marks.GetItemCount(); i++) {
it.iItem = i;
it.iImage = i;
m_Marks.SetItem(&it);
}
UpdateButtons();
g_pMainFrame->CreateMarksTB();
}
void CMarksList::OnClose()
{
CDialog::OnClose();
}
void CMarksList::OnDestroy()
{
m_Marks.SetImageList(NULL, LVSIL_SMALL);
CDialog::OnDestroy();
}
void CMarksList::UpdateButtons()
{
int idx = m_Marks.GetSelectionMark();
if (idx < 0 || m_Marks.GetItemState(idx, LVIS_SELECTED) != LVIS_SELECTED)
idx = -1;
UpdateButtonsEx(idx);
}
void CMarksList::UpdateButtonsEx(int idx)
{
BOOL e = (idx >= 0);
GetDlgItem(IDC_btEditMark)->EnableWindow(e);
GetDlgItem(IDC_btDeleteMark)->EnableWindow(e);
GetDlgItem(IDC_MoveUp)->EnableWindow(e && idx > 0);
GetDlgItem(IDC_MoveDown)->EnableWindow(e && idx < m_Marks.GetItemCount() - 1);
}
void CMarksList::OnClickMarks(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateButtons();
*pResult = 0;
}
void CMarksList::OnDblclkMarks(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateButtons();
if (GetDlgItem(IDC_btEditMark)->IsWindowEnabled())
OnbtEditMark();
*pResult = 0;
}
void CMarksList::OnRclickMarks(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateButtons();
*pResult = 0;
}
void CMarksList::OnRdblclkMarks(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateButtons();
*pResult = 0;
}
void CMarksList::OnOK()
{
UpdateButtons();
if (GetDlgItem(IDC_btEditMark)->IsWindowEnabled())
OnbtEditMark();
}
void CMarksList::OnMoveUp()
{
MoveCategory(m_Marks.GetSelectionMark(), -1);
}
void CMarksList::OnMoveDown()
{
MoveCategory(m_Marks.GetSelectionMark(), 1);
}
void CMarksList::MoveCategory(int Idx, int Delta)
{
CContentObjects& objs = theApp.m_map.Content.Objects;
CContentObj *o;
CContentMark* m;
int i, idx2, cat, d;
CMarkCategory *mc;
CMarkCategories &mcs = theApp.m_map.Content.MarkCategories;
mc = mcs[Idx];
mcs[Idx] = NULL;
mcs.RemoveAt(Idx);
idx2 = Idx + Delta;
mcs.InsertAt(idx2, mc);
d = abs(Delta)/Delta;
CImageList &il = theApp.m_map.Content.MarkImages;
HICON ico = il.ExtractIcon(Idx);
HICON ico2;
i = idx2;
do {
ico2 = il.ExtractIcon(i);
i -= d;
il.Replace(i, ico2);
DestroyIcon(ico2);
}
while (i != Idx);
il.Replace(idx2, ico);
DestroyIcon(ico);
for (i = Idx; i != idx2 + d; i += d)
m_Marks.SetItem(i, 0, LVIF_IMAGE | LVIF_TEXT, mcs[i]->Name, i, 0, 0, NULL);
m_Marks.SetSelectionMark(idx2);
m_Marks.SetItemState(idx2, LVIS_SELECTED, LVIS_SELECTED);
for (i = 0; i < objs.GetSize(); i++) {
o = objs[i];
if (o->GetType() == otMark) {
m = (CContentMark*)o;
cat = m->Category;
if (cat == Idx)
m->Category = idx2;
else
if (cat >= idx2 && cat < Idx)
m->Category++;
else
if (cat <= idx2 && cat > Idx)
m->Category--;
}
}
theApp.m_map.Content.Modified = TRUE;
UpdateButtons();
g_pMainFrame->CreateMarksTB();
}
void CMarksList::FillList()
{
int i;
CMarkCategories &mcs = theApp.m_map.Content.MarkCategories;
m_Marks.DeleteAllItems();
for (i = 0; i < mcs.GetSize(); i++)
m_Marks.InsertItem(i, mcs[i]->Name, i);
}
void CMarksList::OnItemchangedMarks(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
if (pNMListView->uNewState & LVIS_SELECTED)
UpdateButtonsEx(pNMListView->iItem);
*pResult = 0;
}