forked from gopa810/gcal-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DlgRenameCountry.cpp
107 lines (82 loc) · 2.45 KB
/
DlgRenameCountry.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
// DlgRenameCountry.cpp : implementation file
//
#include "stdafx.h"
#include "vcal5beta.h"
#include "DlgRenameCountry.h"
#include "TCountry.h"
#include "Location.h"
#include "GCGlobal.h"
/////////////////////////////////////////////////////////////////////////////
// DlgRenameCountry dialog
DlgRenameCountry::DlgRenameCountry(CWnd* pParent /*=NULL*/)
: CDialog(DlgRenameCountry::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgRenameCountry)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void DlgRenameCountry::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgRenameCountry)
DDX_Control(pDX, IDC_EDIT1, m_Edit);
DDX_Control(pDX, IDC_LIST1, m_List);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgRenameCountry, CDialog)
//{{AFX_MSG_MAP(DlgRenameCountry)
ON_BN_CLICKED(IDC_BUTTON1, OnSaveEdit)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgRenameCountry message handlers
void DlgRenameCountry::OnSaveEdit()
{
// TODO: Add your control notification handler code here
CString str;
CString strOld;
CString str2;
int idx;
WORD w;
m_Edit.GetWindowText(str);
idx = m_List.GetItemData(nSelected);
if (nSelected >= 0)
{
strOld = TCountry::GetCountryNameByIndex(idx);
TCountry::SetCountryName(idx, (LPCTSTR)str);
str2.Format("%s [%s]", str, TCountry::GetCountryAcronymByIndex(idx));
w = TCountry::GetCountryCode(idx);
m_List.InsertString(nSelected, str2);
m_List.DeleteString(nSelected + 1);
m_List.SetItemData(nSelected, idx);
m_List.SetCurSel(nSelected);
CLocationList::RenameCountry((LPCTSTR)strOld, str);
}
}
void DlgRenameCountry::OnSelChange()
{
// TODO: Add your control notification handler code here
int n = m_List.GetCurSel();
int idx = m_List.GetItemData(n);
nSelected = n;
m_Edit.SetWindowText(TCountry::GetCountryNameByIndex(idx));
}
BOOL DlgRenameCountry::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString str;
int n, cnt, b;
cnt = TCountry::GetCountryCount();
for(n = 0; n < cnt; n++)
{
str.Format("%s [%s]", TCountry::GetCountryNameByIndex(n),
TCountry::GetCountryAcronymByIndex(n));
b = m_List.AddString(str);
m_List.SetItemData(b, n);
}
nSelected = -1;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}