2 * @file LoadSaveCodepageDlg.cpp
4 * @brief Implementation of the dialog used to select codepages
8 #include "LoadSaveCodepageDlg.h"
10 #include "ExConverter.h"
16 /////////////////////////////////////////////////////////////////////////////
17 // CLoadSaveCodepageDlg dialog
20 CLoadSaveCodepageDlg::CLoadSaveCodepageDlg(int nFiles, CWnd* pParent /*= nullptr*/)
21 : CTrDialog(CLoadSaveCodepageDlg::IDD, pParent)
22 , m_bAffectsLeft(true)
23 , m_bAffectsMiddle(true)
24 , m_bAffectsRight(true)
25 , m_bLoadSaveSameCodepage(true)
26 // String m_sAffectsLeftString
27 // String m_sAffectsRightString
28 , m_bSaveCodepageBOM(false)
31 , m_bEnableSaveCodepage(false)
34 //{{AFX_DATA_INIT(CLoadSaveCodepageDlg)
35 // NOTE: the ClassWizard will add member initialization here
39 void CLoadSaveCodepageDlg::SetLeftRightAffectStrings(const String & sAffectsLeft, const String & sAffectsMiddle, const String & sAffectsRight)
41 m_sAffectsLeftString = sAffectsLeft;
42 m_sAffectsMiddleString = sAffectsMiddle;
43 m_sAffectsRightString = sAffectsRight;
46 void CLoadSaveCodepageDlg::DoDataExchange(CDataExchange* pDX)
48 CTrDialog::DoDataExchange(pDX);
49 //{{AFX_DATA_MAP(CLoadSaveCodepageDlg)
50 DDX_Check(pDX, IDC_AFFECTS_LEFT_BTN, m_bAffectsLeft);
51 DDX_Check(pDX, IDC_AFFECTS_MIDDLE_BTN, m_bAffectsMiddle);
52 DDX_Check(pDX, IDC_AFFECTS_RIGHT_BTN, m_bAffectsRight);
53 DDX_Check(pDX, IDC_LOAD_SAVE_SAME_CODEPAGE, m_bLoadSaveSameCodepage);
54 DDX_Control(pDX, IDC_AFFECTS_LEFT_BTN, m_AffectsLeftBtn);
55 DDX_Control(pDX, IDC_AFFECTS_MIDDLE_BTN, m_AffectsMiddleBtn);
56 DDX_Control(pDX, IDC_AFFECTS_RIGHT_BTN, m_AffectsRightBtn);
57 DDX_Text(pDX, IDC_LOAD_CODEPAGE_TEXTBOX, m_nLoadCodepage);
58 DDX_Text(pDX, IDC_SAVE_CODEPAGE_TEXTBOX, m_nSaveCodepage);
59 DDX_Check(pDX, IDC_SAVE_CODEPAGE_BOM, m_bSaveCodepageBOM);
64 BEGIN_MESSAGE_MAP(CLoadSaveCodepageDlg, CTrDialog)
65 //{{AFX_MSG_MAP(CLoadSaveCodepageDlg)
66 ON_BN_CLICKED(IDC_AFFECTS_LEFT_BTN, OnAffectsLeftBtnClicked)
67 ON_BN_CLICKED(IDC_AFFECTS_MIDDLE_BTN, OnAffectsMiddleBtnClicked)
68 ON_BN_CLICKED(IDC_AFFECTS_RIGHT_BTN, OnAffectsRightBtnClicked)
69 ON_BN_CLICKED(IDC_LOAD_SAVE_SAME_CODEPAGE, OnLoadSaveSameCodepage)
73 /////////////////////////////////////////////////////////////////////////////
74 // CLoadSaveCodepageDlg message handlers
77 * @brief Handler for WM_INITDIALOG; conventional location to initialize controls
78 * At this point dialog and control windows exist
80 BOOL CLoadSaveCodepageDlg::OnInitDialog()
82 CTrDialog::OnInitDialog();
84 IExconverter *pexconv = Exconverter::getInstance();
85 if (pexconv != nullptr)
87 CComboBox combol, combos;
88 combol.Attach(::GetDlgItem(m_hWnd, IDC_LOAD_CODEPAGE_TEXTBOX));
89 combos.Attach(::GetDlgItem(m_hWnd, IDC_SAVE_CODEPAGE_TEXTBOX));
90 std::vector<CodePageInfo> cpi = pexconv->enumCodePages();
91 for (size_t i = 0, j = 0; i < cpi.size(); i++)
93 String desc = strutils::format(_T("%05d - %s"), cpi[i].codepage, cpi[i].desc);
94 combol.AddString(desc.c_str());
95 combos.AddString(desc.c_str());
96 if (cpi[i].codepage == m_nLoadCodepage)
98 combol.SetCurSel(static_cast<int>(j));
99 combos.SetCurSel(static_cast<int>(j));
110 SetDlgItemText(IDC_LEFT_FILES_LABEL, m_sAffectsLeftString);
111 SetDlgItemText(IDC_MIDDLE_FILES_LABEL, m_sAffectsMiddleString);
112 SetDlgItemText(IDC_RIGHT_FILES_LABEL, m_sAffectsRightString);
117 EnableDlgItem(IDC_AFFECTS_MIDDLE_BTN, false);
119 return FALSE; // return TRUE unless you set the focus to a control
120 // EXCEPTION: OCX Property Pages should return FALSE
124 * @brief If user unchecks left, then check right (to ensure never have nothing checked)
126 void CLoadSaveCodepageDlg::OnAffectsLeftBtnClicked()
128 if (m_AffectsLeftBtn.GetCheck() != BST_CHECKED)
131 m_AffectsRightBtn.SetCheck(BST_CHECKED);
134 if (m_AffectsMiddleBtn.GetCheck() != BST_CHECKED)
136 if (m_AffectsRightBtn.GetCheck() != BST_CHECKED)
137 m_AffectsRightBtn.SetCheck(BST_CHECKED);
144 * @brief If user unchecks middle, then check right (to ensure never have nothing checked)
146 void CLoadSaveCodepageDlg::OnAffectsMiddleBtnClicked()
148 if (m_AffectsMiddleBtn.GetCheck() != BST_CHECKED)
150 if (m_AffectsLeftBtn.GetCheck() != BST_CHECKED)
152 if (m_AffectsRightBtn.GetCheck() != BST_CHECKED)
153 m_AffectsLeftBtn.SetCheck(BST_CHECKED);
159 * @brief If user unchecks right, then check left (to ensure never have nothing checked)
161 void CLoadSaveCodepageDlg::OnAffectsRightBtnClicked()
163 if (m_AffectsRightBtn.GetCheck() != BST_CHECKED)
166 m_AffectsLeftBtn.SetCheck(BST_CHECKED);
169 if (m_AffectsMiddleBtn.GetCheck() != BST_CHECKED)
171 if (m_AffectsLeftBtn.GetCheck() != BST_CHECKED)
172 m_AffectsLeftBtn.SetCheck(BST_CHECKED);
179 * @brief Disable save group if save codepage slaved to load codepage
181 void CLoadSaveCodepageDlg::OnLoadSaveSameCodepage()
187 * @brief Disable save group if save codepage slaved to load codepage
189 void CLoadSaveCodepageDlg::UpdateSaveGroup()
191 UpdateDataFromWindow();
192 if (!m_bEnableSaveCodepage)
193 EnableDlgItem(IDC_LOAD_SAVE_SAME_CODEPAGE, false);
194 bool EnableSave = m_bEnableSaveCodepage && !m_bLoadSaveSameCodepage;
195 EnableDlgItem(IDC_SAVE_CODEPAGE_TEXTBOX, EnableSave);
196 EnableDlgItem(IDC_SAVE_CODEPAGE_BOM, EnableSave);
200 * @brief User pressed Ok, ensure data members set correctly
202 void CLoadSaveCodepageDlg::OnOK ()
205 if (m_bLoadSaveSameCodepage)
207 m_nSaveCodepage = m_nLoadCodepage;