OSDN Git Service

crystaledit: Make almost the same code into a common function
[winmerge-jp/winmerge-jp.git] / Externals / crystaledit / editlib / chcondlg.cpp
1 ///////////////////////////////////////////////////////////////////////////
2 //  File:    chcondlg.cpp
3 //  Version: 1.6.0.9
4 //  Updated: 17-Oct-1999
5 //
6 //  Copyright:  Ferdinand Prantl
7 //  E-mail:     prantl@ff.cuni.cz
8 //
9 //  Character encoding dialog
10 //
11 //  You are free to use or modify this code to the following restrictions:
12 //  - Acknowledge me somewhere in your about box, simple "Parts of code by.."
13 //  will be enough. If you can't (or don't want to), contact me personally.
14 //  - LEAVE THIS HEADER INTACT
15 ////////////////////////////////////////////////////////////////////////////
16
17 #include "StdAfx.h"
18 #include "chcondlg.h"
19 #include "ccrystaltextview.h"
20 #include "cs2cs.h"
21
22 #include "DDXHelper.h"
23
24 #ifdef _DEBUG
25 #define new DEBUG_NEW
26 #endif
27
28 EDITPADC_CLASS LPCTSTR pszCodeNames[] =
29   {
30     _T ("ASCII (without accents)"),
31     _T ("MS-Windows CP 1250"),
32     _T ("MS-Windows CP 1252"),
33     _T ("PC Latin I (CP 850)"),
34     _T ("PC Latin II (CP 852)"),
35     _T ("IBM Latin II (IBM 852)"),
36     _T ("ISO-8859-1"),
37     _T ("ISO-8859-2"),
38     _T ("Brothers Kamenicky"),
39     _T ("KOI8-CS"),
40     _T ("Apple Macintosh"),
41     _T ("Apple Macintosh for Central Europe"),
42     _T ("Corky"),
43     nullptr
44   };
45
46 EDITPADC_CLASS int nCodeNames = sizeof (pszCodeNames) / sizeof (pszCodeNames[0]) - 1;
47
48 EDITPADC_CLASS void FillComboBox (CComboBox &Control, LPCTSTR *pszItems)
49 {
50   Control.ResetContent();
51   ASSERT (pszItems != nullptr);
52   while (*pszItems)
53     Control.AddString(*pszItems++);
54 }
55
56 /////////////////////////////////////////////////////////////////////////////
57 // CCharConvDlg dialog
58
59 CCharConvDlg::CCharConvDlg () : CDialog (CCharConvDlg::IDD, nullptr)
60 , m_nSource(1)
61 , m_nDest(1)
62 , m_bAlpha(false)
63 , m_sPreview(_T(""))
64 {
65     //{{AFX_DATA_INIT(CCharConvDlg)
66     //}}AFX_DATA_INIT
67 }
68
69 void CCharConvDlg::
70 DoDataExchange (CDataExchange * pDX)
71 {
72   CDialog::DoDataExchange (pDX);
73     //{{AFX_DATA_MAP(CCharConvDlg)
74     DDX_Control(pDX, IDC_SRC, m_ctlSource);
75     DDX_Control(pDX, IDC_DEST, m_ctlDest);
76     DDX_CBIndex(pDX, IDC_SRC, m_nSource);
77     DDX_CBIndex(pDX, IDC_DEST, m_nDest);
78     DDX_Check(pDX, IDC_ALPHA_ONLY, m_bAlpha);
79     DDX_Text(pDX, IDC_PREVIEW, m_sPreview);
80     //}}AFX_DATA_MAP
81 }
82
83 BEGIN_MESSAGE_MAP (CCharConvDlg, CDialog)
84     //{{AFX_MSG_MAP(CCharConvDlg)
85     ON_BN_CLICKED(IDPREVIEW, OnPreview)
86     //}}AFX_MSG_MAP
87 END_MESSAGE_MAP ()
88
89 /////////////////////////////////////////////////////////////////////////////
90 // CCharConvDlg message handlers
91
92 static int nSource = 1;
93 static int nDest = 1;
94
95 BOOL CCharConvDlg::
96 OnInitDialog ()
97 {
98   CDialog::OnInitDialog ();
99   FillComboBox (m_ctlSource, pszCodeNames);
100   FillComboBox (m_ctlDest, pszCodeNames);
101   m_nSource = nSource;
102   m_nDest = nSource;
103   m_sPreview = m_sOriginal;
104   UpdateData (false);
105   return true;
106 }
107
108 void CCharConvDlg::OnOK ()
109 {
110   CDialog::OnOK ();
111   nSource = m_nSource;
112   nDest = m_nSource;
113 }
114
115 void CCharConvDlg::OnPreview() 
116 {
117   UpdateData ();
118   LPTSTR pszNew = nullptr;
119   if (!iconvert_new (m_sOriginal, &pszNew, m_nSource, m_nDest, m_bAlpha))
120     {
121       m_sPreview = pszNew;
122       UpdateData (false);
123     }
124   if (pszNew != nullptr)
125     free (pszNew);
126 }