OSDN Git Service

Leave the class name as CIniOptionsMgr, but rename the filename to IniOptionsMgr.*
[winmerge-jp/winmerge-jp.git] / Src / PropEditor.cpp
1 /** 
2  * @file  PropEditor.cpp
3  *
4  * @brief Implementation of PropEditor propertysheet
5  */
6
7 #include "stdafx.h"
8 #include "PropEditor.h"
9 #include "OptionsDef.h"
10 #include "OptionsMgr.h"
11 #include "OptionsPanel.h"
12
13 #ifdef _DEBUG
14 #define new DEBUG_NEW
15 #endif
16
17 /** @brief Maximum size for tabs in spaces. */
18 static const int MAX_TABSIZE = 64;
19
20 /** 
21  * @brief Constructor.
22  * @param [in] optionsMgr Pointer to options manager for handling options.
23  */
24 PropEditor::PropEditor(COptionsMgr *optionsMgr) 
25 : OptionsPanel(optionsMgr, PropEditor::IDD)
26 , m_bHiliteSyntax(false)
27 , m_nTabType(-1)
28 , m_nTabSize(0)
29 , m_bAutomaticRescan(false)
30 , m_bAllowMixedEol(false)
31 , m_bCopyFullLine(false)
32 , m_bViewLineDifferences(false)
33 , m_bBreakOnWords(false)
34 , m_nBreakType(0)
35 , m_nRenderingMode(0)
36 {
37 }
38
39 /** 
40  * @brief Function handling dialog data exchange between GUI and variables.
41  */
42 void PropEditor::DoDataExchange(CDataExchange* pDX)
43 {
44         CDialog::DoDataExchange(pDX);
45         //{{AFX_DATA_MAP(PropEditor)
46         DDX_Check(pDX, IDC_HILITE_CHECK, m_bHiliteSyntax);
47         DDX_Radio(pDX, IDC_PROP_INSERT_TABS, m_nTabType);
48         DDX_Text(pDX, IDC_TAB_EDIT, m_nTabSize);
49         DDV_MaxChars(pDX, std::to_string(m_nTabSize).c_str(), 2);
50         DDX_Check(pDX, IDC_AUTOMRESCAN_CHECK, m_bAutomaticRescan);
51         DDX_Check(pDX, IDC_MIXED_EOL, m_bAllowMixedEol);
52         // m_bCopyFullLine currently is only a hidden option
53         //  > it is used here in PropEditor.cpp, because otherwise it doesn't get saved to the registry
54         DDX_Check(pDX, IDC_VIEW_LINE_DIFFERENCES, m_bViewLineDifferences);
55         DDX_Radio(pDX, IDC_EDITOR_CHARLEVEL, m_bBreakOnWords);
56         DDX_CBIndex(pDX, IDC_BREAK_TYPE, m_nBreakType);
57         DDX_Text(pDX, IDC_BREAK_CHARS, m_breakChars);
58         DDX_CBIndex(pDX, IDC_RENDERING_MODE, m_nRenderingMode);
59         //}}AFX_DATA_MAP
60 }
61
62
63 BEGIN_MESSAGE_MAP(PropEditor, OptionsPanel)
64         //{{AFX_MSG_MAP(PropEditor)
65         ON_BN_CLICKED(IDC_VIEW_LINE_DIFFERENCES, OnLineDiffControlClicked)
66         ON_BN_CLICKED(IDC_EDITOR_CHARLEVEL, OnLineDiffControlClicked)
67         ON_BN_CLICKED(IDC_EDITOR_WORDLEVEL, OnLineDiffControlClicked)
68         ON_EN_KILLFOCUS(IDC_TAB_EDIT, OnEnKillfocusTabEdit)
69         //}}AFX_MSG_MAP
70 END_MESSAGE_MAP()
71
72 /** 
73  * @brief Reads options values from storage to UI.
74  */
75 void PropEditor::ReadOptions()
76 {
77         m_nTabSize = GetOptionsMgr()->GetInt(OPT_TAB_SIZE);
78         m_nTabType = GetOptionsMgr()->GetInt(OPT_TAB_TYPE);
79         m_bAutomaticRescan = GetOptionsMgr()->GetBool(OPT_AUTOMATIC_RESCAN);
80         m_bHiliteSyntax = GetOptionsMgr()->GetBool(OPT_SYNTAX_HIGHLIGHT);
81         m_bAllowMixedEol = GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL);
82         m_bCopyFullLine = GetOptionsMgr()->GetBool(OPT_COPY_FULL_LINE);
83         m_bViewLineDifferences = GetOptionsMgr()->GetBool(OPT_WORDDIFF_HIGHLIGHT);
84         m_bBreakOnWords = GetOptionsMgr()->GetBool(OPT_BREAK_ON_WORDS);
85         m_nBreakType = GetOptionsMgr()->GetInt(OPT_BREAK_TYPE);
86         m_breakChars = GetOptionsMgr()->GetString(OPT_BREAK_SEPARATORS);
87         m_nRenderingMode = GetOptionsMgr()->GetInt(OPT_RENDERING_MODE) + 1;
88 }
89
90 /** 
91  * @brief Writes options values from UI to storage.
92  */
93 void PropEditor::WriteOptions()
94 {
95         // Sanity check tabsize
96         if (m_nTabSize < 1)
97                 m_nTabSize = 1;
98         if (m_nTabSize > MAX_TABSIZE)
99                 m_nTabSize = MAX_TABSIZE;
100         GetOptionsMgr()->SaveOption(OPT_TAB_SIZE, (int)m_nTabSize);
101         GetOptionsMgr()->SaveOption(OPT_TAB_TYPE, (int)m_nTabType);
102         GetOptionsMgr()->SaveOption(OPT_AUTOMATIC_RESCAN, m_bAutomaticRescan);
103         GetOptionsMgr()->SaveOption(OPT_ALLOW_MIXED_EOL, m_bAllowMixedEol);
104         GetOptionsMgr()->SaveOption(OPT_COPY_FULL_LINE, m_bCopyFullLine);
105         GetOptionsMgr()->SaveOption(OPT_SYNTAX_HIGHLIGHT, m_bHiliteSyntax);
106         GetOptionsMgr()->SaveOption(OPT_WORDDIFF_HIGHLIGHT, m_bViewLineDifferences);
107         GetOptionsMgr()->SaveOption(OPT_BREAK_ON_WORDS, m_bBreakOnWords);
108         GetOptionsMgr()->SaveOption(OPT_BREAK_TYPE, m_nBreakType);
109         GetOptionsMgr()->SaveOption(OPT_BREAK_SEPARATORS, String(m_breakChars));
110         GetOptionsMgr()->SaveOption(OPT_RENDERING_MODE, m_nRenderingMode - 1);
111 }
112
113 /** 
114  * @brief Called before propertysheet is drawn.
115  */
116 BOOL PropEditor::OnInitDialog() 
117 {
118         OptionsPanel::OnInitDialog();
119
120         LoadComboBoxStrings();
121         UpdateDataToWindow();
122         UpdateLineDiffControls();
123 #ifndef _WIN64
124         EnableDlgItem(IDC_RENDERING_MODE, false);
125 #endif
126
127         return TRUE;  // return TRUE unless you set the focus to a control
128                       // EXCEPTION: OCX Property Pages should return FALSE
129 }
130
131 /**
132  * @brief Load strings (from resource) into combobox for break type
133  */
134 void PropEditor::LoadComboBoxStrings()
135 {
136         CComboBox * cbo = (CComboBox *)GetDlgItem(IDC_BREAK_TYPE);
137         cbo->AddString(_("Break at whitespace").c_str());
138         cbo->AddString(_("Break at whitespace or punctuation").c_str());
139         cbo = (CComboBox *)GetDlgItem(IDC_RENDERING_MODE);
140         cbo->AddString(_("GDI").c_str());
141         cbo->AddString(_("DirectWrite Default").c_str());
142         cbo->AddString(_("DirectWrite Aliased").c_str());
143         cbo->AddString(_("DirectWrite GDI Classic").c_str());
144         cbo->AddString(_("DirectWrite GDI Natural").c_str());
145         cbo->AddString(_("DirectWrite Natural").c_str());
146         cbo->AddString(_("DirectWrite Natural Symmetric").c_str());
147 }
148
149 /**
150  * @brief Handlers any clicks in any of the line differencing controls
151  */
152 void PropEditor::OnLineDiffControlClicked()
153 {
154         UpdateLineDiffControls();
155 }
156
157 /** 
158  * @brief Update availability of line difference controls
159  */
160 void PropEditor::UpdateLineDiffControls()
161 {
162         UpdateDataFromWindow();
163         // Can only choose char/word level if line differences are enabled
164         EnableDlgItem(IDC_EDITOR_CHARLEVEL, m_bViewLineDifferences);
165         EnableDlgItem(IDC_EDITOR_WORDLEVEL, m_bViewLineDifferences);
166         // Can only choose break type if line differences are enabled & we're breaking on words
167         EnableDlgItem(IDC_BREAK_TYPE, m_bViewLineDifferences);
168 }
169
170 /** 
171  * @brief Check tabsize value when control loses focus.
172  */
173 void PropEditor::OnEnKillfocusTabEdit()
174 {
175         unsigned value = GetDlgItemInt(IDC_TAB_EDIT);
176         if (value < 1 || value > MAX_TABSIZE)
177         {
178                 String msg = strutils::format_string1(
179                         _("Value in Tab size -field is not in range WinMerge accepts.\n\nPlease use values 1 - %1."),
180                         strutils::to_str(MAX_TABSIZE));
181                 AfxMessageBox(msg.c_str(), MB_ICONWARNING);
182         }
183 }