-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDlgSelectMarkerType.cpp
More file actions
120 lines (104 loc) · 3.27 KB
/
DlgSelectMarkerType.cpp
File metadata and controls
120 lines (104 loc) · 3.27 KB
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
// DlgSelectMarkerType.cpp : implementation file
//
#include "stdafx.h"
#include "krs.h"
#include "DlgSelectMarkerType.h"
#include "DlgEditMarkerType.h"
#include <CHECK.h>
#include <DB.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgSelectMarkerType dialog
DlgSelectMarkerType::DlgSelectMarkerType(bool for_select, CWnd* pParent /*=NULL*/)
: CDialog(DlgSelectMarkerType::IDD, pParent),
m_for_select (for_select)
{
//{{AFX_DATA_INIT(DlgSelectMarkerType)
//}}AFX_DATA_INIT
}
void DlgSelectMarkerType::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgSelectMarkerType)
DDX_Control(pDX, IDC_LIST_MARKER_TYPES, m_marker_types_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgSelectMarkerType, CDialog)
//{{AFX_MSG_MAP(DlgSelectMarkerType)
ON_BN_CLICKED(IDC_BUTTON_SELECT, OnButtonSelect)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_LBN_SELCHANGE(IDC_LIST_MARKER_TYPES, OnSelchangeListMarkerTypes)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL DlgSelectMarkerType::OnInitDialog()
{
CDialog::OnInitDialog();
if (!m_for_select)
SetDlgItemText(IDC_BUTTON_SELECT, "Ðåäàêòèðîâàòü");
int i;
map<int, BS_MarkerType>::iterator current = DB_marker_types.begin();
while (current != DB_marker_types.end())
{
i = m_marker_types_list.AddString(current->second.m_name);
m_marker_types_list.SetItemData(i, current->second.m_index);
current++;
}
return TRUE;
}
void DlgSelectMarkerType::OnButtonSelect()
{
if (!m_for_select)
{
int list_index = m_marker_types_list.GetCurSel();
CHECK(list_index >= 0);
int marker_type_index = m_marker_types_list.GetItemData(list_index);
CHECK(marker_type_index > 0);
CHECK(DB_marker_types.find(marker_type_index) != DB_marker_types.end());
BS_MarkerType* mt = &DB_marker_types[marker_type_index];
DlgEditMarkerType dlg(mt);
if (dlg.DoModal() == IDOK)
{
m_marker_types_list.InsertString(list_index, mt->m_name);
m_marker_types_list.DeleteString(list_index + 1);
m_marker_types_list.SetCurSel(list_index);
}
}
else
CDialog::OnOK();
}
void DlgSelectMarkerType::OnButtonAdd()
{
BS_MarkerType new_marker_type;
DlgEditMarkerType dlg(&new_marker_type);
if (dlg.DoModal() == IDOK)
{
int list_index = m_marker_types_list.AddString(new_marker_type.m_name);
m_marker_types_list.SetItemData(list_index, new_marker_type.m_index);
m_marker_types_list.SetCurSel(list_index);
OnSelchangeListMarkerTypes();
}
}
void DlgSelectMarkerType::OnSelchangeListMarkerTypes()
{
BOOL ena = (m_marker_types_list.GetCurSel() >= 0);
GetDlgItem(IDC_BUTTON_SELECT)->EnableWindow(ena);
GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(ena);
}
void DlgSelectMarkerType::OnButtonDelete()
{
int list_index = m_marker_types_list.GetCurSel();
CHECK(list_index >= 0);
int marker_type_index = m_marker_types_list.GetItemData(list_index);
CHECK(marker_type_index > 0);
CHECK(DB_marker_types.find(marker_type_index) != DB_marker_types.end());
if (MessageBox("Óäàëèòü òèï ìàðêåðà?", "Óäàëåíèå òèïà ìàðêåðà", MB_YESNO) != IDYES)
return;
DB_marker_types.erase(marker_type_index);
m_marker_types_list.DeleteString(list_index);
OnSelchangeListMarkerTypes();
}