OSDN Git Service

refactor
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 4 Jun 2023 06:09:15 +0000 (15:09 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 4 Jun 2023 06:09:15 +0000 (15:09 +0900)
12 files changed:
Src/ConfirmFolderCopyDlg.cpp
Src/PatchDlg.cpp
Src/PropCodepage.cpp
Src/PropCompare.cpp
Src/PropCompareFolder.cpp
Src/PropCompareImage.cpp
Src/PropCompareWebPage.cpp
Src/PropEditor.cpp
Src/PropGeneral.cpp
Src/SelectPluginDlg.cpp
Src/TrDialogs.h
Src/WebPageDiffFrm.cpp

index 06480de..b4a1718 100644 (file)
@@ -68,7 +68,7 @@ BOOL ConfirmFolderCopyDlg::OnInitDialog()
                SendDlgItemMessage(IDC_FLDCONFIRM_ICON, STM_SETICON, (WPARAM)icon, 0L);
 
                if (!m_caption.empty())
-                       SetWindowText(m_caption.c_str());
+                       SetTitleText(m_caption);
 
                // setup handler for resizing this dialog       
                m_constraint.InitializeCurrentSize(this);
@@ -78,7 +78,7 @@ BOOL ConfirmFolderCopyDlg::OnInitDialog()
                m_constraint.LoadPosition(_T("ResizeableDialogs"), _T("FolderCopyConfirmDlg"), false);
 
                String strDontAskAgain = LoadResString(IDS_MESSAGEBOX_DONT_ASK_AGAIN);
-               GetDlgItem(IDC_FLDCONFIRM_DONTASKAGAIN)->SetWindowText(strDontAskAgain.c_str());
+               SetDlgItemText(IDC_FLDCONFIRM_DONTASKAGAIN, strDontAskAgain);
        }
 
        return TRUE;  // return TRUE unless you set the focus to a control
index c45a3ca..0057272 100644 (file)
@@ -222,10 +222,8 @@ BOOL CPatchDlg::OnInitDialog()
        UpdateData(FALSE);
 
        // Add patch styles to combobox
-       m_comboStyle.AddString(_("Normal").c_str());
-       m_comboStyle.AddString(_("Context").c_str());
-       m_comboStyle.AddString(_("Unified").c_str());
-       m_comboStyle.AddString(_("HTML").c_str());
+       SetDlgItemComboBoxList(IDC_DIFF_STYLE,
+               { _("Normal"), _("Context"), _("Unified"), _("HTML") });
 
        m_outputStyle = OUTPUT_NORMAL;
        m_comboStyle.SetCurSel(0);
@@ -233,11 +231,8 @@ BOOL CPatchDlg::OnInitDialog()
        // Add default context line counts to combobox if its empty
        if (m_comboContext.GetCount() == 0)
        {
-               m_comboContext.AddString(_T("0"));
-               m_comboContext.AddString(_T("1"));
-               m_comboContext.AddString(_T("3"));
-               m_comboContext.AddString(_T("5"));
-               m_comboContext.AddString(_T("7"));
+               SetDlgItemComboBoxList(IDC_DIFF_CONTEXT,
+                       { _T("0"), _T("1"), _T("3"), _T("5"), _T("7") });
        }
        
        LoadSettings();
@@ -367,10 +362,8 @@ void CPatchDlg::UpdateSettings()
 
        m_comboContext.SelectString(-1, strutils::to_str(m_contextLines).c_str());
 
-       if (m_outputStyle == OUTPUT_CONTEXT || m_outputStyle == OUTPUT_UNIFIED || m_outputStyle == OUTPUT_HTML)
-               m_comboContext.EnableWindow(TRUE);
-       else
-               m_comboContext.EnableWindow(FALSE);
+       bool enabled = (m_outputStyle == OUTPUT_CONTEXT || m_outputStyle == OUTPUT_UNIFIED || m_outputStyle == OUTPUT_HTML);
+       m_comboContext.EnableWindow(enabled);
 }
 
 /** 
index 56681c3..01044f7 100644 (file)
@@ -90,10 +90,9 @@ BOOL PropCodepage::OnInitDialog()
        
        // Enable/disable "Custom codepage" edit field
        EnableDlgItem(IDC_CUSTOM_CP_NUMBER, IsDlgButtonChecked(IDC_CP_CUSTOM) == 1);
-       m_comboAutodetectType.EnableWindow(
-               IsDlgButtonChecked(IDC_DETECT_CODEPAGE2) == 1);
+       EnableDlgItem(IDC_DETECT_AUTODETECTTYPE, IsDlgButtonChecked(IDC_DETECT_CODEPAGE2) == 1);
 
-       m_comboCustomCodepageValue.SetWindowText(strutils::to_str(m_nCustomCodepageValue).c_str());
+       SetDlgItemInt(IDC_CUSTOM_CP_NUMBER, m_nCustomCodepageValue);
 
        IExconverter *pexconv = Exconverter::getInstance();
        if (pexconv != nullptr)
@@ -153,8 +152,7 @@ void PropCodepage::OnCpCustom()
 
 void PropCodepage::OnDetectCodepage2() 
 {
-       m_comboAutodetectType.EnableWindow(
-               IsDlgButtonChecked(IDC_DETECT_CODEPAGE2) == 1);
+       EnableDlgItem(IDC_DETECT_AUTODETECTTYPE, IsDlgButtonChecked(IDC_DETECT_CODEPAGE2) == 1);
 }
 
 void PropCodepage::OnDetectAutodetecttype()
index 16780cb..4dfb73f 100644 (file)
@@ -110,10 +110,8 @@ void PropCompare::WriteOptions()
  */
 BOOL PropCompare::OnInitDialog()
 {
-       CComboBox * combo = (CComboBox*) GetDlgItem(IDC_DIFF_ALGORITHM);
-       for (const auto& item : { _("default"), _("minimal"), _("patience"), _("histogram"), _("none") })
-               combo->AddString(item.c_str());
-       combo->SetCurSel(m_nDiffAlgorithm);
+       SetDlgItemComboBoxList(IDC_DIFF_ALGORITHM,
+               { _("default"), _("minimal"), _("patience"), _("histogram"), _("none") });
 
        OptionsPanel::OnInitDialog();
        return TRUE;  // return TRUE unless you set the focus to a control
index d9ec1cc..0ccf973 100644 (file)
@@ -118,12 +118,11 @@ void PropCompareFolder::WriteOptions()
  */
 BOOL PropCompareFolder::OnInitDialog() 
 {
-       OptionsPanel::OnInitDialog();
-       CComboBox * combo = (CComboBox*) GetDlgItem(IDC_COMPAREMETHODCOMBO);
+       SetDlgItemComboBoxList(IDC_COMPAREMETHODCOMBO,
+               { _("Full Contents"), _("Quick Contents"), _("Binary Contents"), _("Modified Date"), _("Modified Date and Size"), _("Size") });
 
-       for (const auto& item : { _("Full Contents"), _("Quick Contents"), _("Binary Contents"), _("Modified Date"), _("Modified Date and Size"), _("Size") })
-               combo->AddString(item.c_str());
-       combo->SetCurSel(m_compareMethod);
+       OptionsPanel::OnInitDialog();
+       
        UpdateControls();
 
        return TRUE;  // return TRUE unless you set the focus to a control
index a30c185..1e0a095 100644 (file)
@@ -76,10 +76,8 @@ void PropCompareImage::WriteOptions()
  */
 BOOL PropCompareImage::OnInitDialog()
 {
-       CComboBox * combo = (CComboBox*) GetDlgItem(IDC_COMPAREIMAGE_OCR_RESULT_TYPE);
-       for (const auto& item : { _("Text only"), _("Line-by-line position and text"), _("Word-by-word position and text") })
-               combo->AddString(item.c_str());
-       combo->SetCurSel(m_nOcrResultType);
+       SetDlgItemComboBoxList(IDC_COMPAREIMAGE_OCR_RESULT_TYPE,
+               { _("Text only"), _("Line-by-line position and text"), _("Word-by-word position and text") });
 
        OptionsPanel::OnInitDialog();
        return TRUE;  // return TRUE unless you set the focus to a control
index 1b6dedf..92b9cd9 100644 (file)
@@ -74,10 +74,8 @@ void PropCompareWebPage::WriteOptions()
  */
 BOOL PropCompareWebPage::OnInitDialog()
 {
-       CComboBox * combo = (CComboBox*) GetDlgItem(IDC_COMPAREWEBPAGE_USERDATAFOLDER_TYPE);
-       for (const auto& item : { _("AppData folder"), _("Install folder") })
-               combo->AddString(item.c_str());
-       combo->SetCurSel(m_nUserDataFolderType);
+       SetDlgItemComboBoxList(IDC_COMPAREWEBPAGE_USERDATAFOLDER_TYPE,
+               { _("AppData folder"), _("Install folder") });
 
        OptionsPanel::OnInitDialog();
        return TRUE;  // return TRUE unless you set the focus to a control
index a477c0b..4784810 100644 (file)
@@ -133,12 +133,10 @@ BOOL PropEditor::OnInitDialog()
  */
 void PropEditor::LoadComboBoxStrings()
 {
-       CComboBox * cbo = (CComboBox *)GetDlgItem(IDC_BREAK_TYPE);
-       for (const auto& item : { _("Break at whitespace"), _("Break at whitespace or punctuation") })
-               cbo->AddString(item.c_str());
-       cbo = (CComboBox *)GetDlgItem(IDC_RENDERING_MODE);
-       for (const auto& item : { _("GDI"), _("DirectWrite Default"), _("DirectWrite Aliased"), _("DirectWrite GDI Classic"), _("DirectWrite GDI Natural"), _("DirectWrite Natural"), _("DirectWrite Natural Symmetric") })
-               cbo->AddString(item.c_str());
+       SetDlgItemComboBoxList(IDC_BREAK_TYPE,
+               { _("Break at whitespace"), _("Break at whitespace or punctuation") });
+       SetDlgItemComboBoxList(IDC_RENDERING_MODE,
+               { _("GDI"), _("DirectWrite Default"), _("DirectWrite Aliased"), _("DirectWrite GDI Classic"), _("DirectWrite GDI Natural"), _("DirectWrite Natural"), _("DirectWrite Natural Symmetric") });
 }
 
 /**
index 31af99d..580a46e 100644 (file)
@@ -48,39 +48,16 @@ PropGeneral::~PropGeneral()
 
 BOOL PropGeneral::OnInitDialog()
 {
-       OptionsPanel::OnInitDialog();
-
-       CComboBox *pWnd = (CComboBox*)GetDlgItem(IDC_AUTO_COMPLETE_SOURCE);
-       ASSERT(pWnd != nullptr);
-
-       for (const auto& item : { _("Disabled"), _("From file system"), _("From Most Recently Used list") })
-               pWnd->AddString(item.c_str());
-
-       pWnd->SetCurSel(m_nAutoCompleteSource);
-
-       pWnd = (CComboBox*)GetDlgItem(IDC_ESC_CLOSES_WINDOW);
-       ASSERT(pWnd != nullptr);
-
-       for (const auto& item : { _("Disabled"), _("MDI child window or main window"), _("MDI child window only"), _("Close main window if there is only one MDI child window") })
-               pWnd->AddString(item.c_str());
-
-       pWnd->SetCurSel(m_nCloseWindowWithEsc);
+       SetDlgItemComboBoxList(IDC_AUTO_COMPLETE_SOURCE,
+               { _("Disabled"), _("From file system"), _("From Most Recently Used list") });
+       SetDlgItemComboBoxList(IDC_ESC_CLOSES_WINDOW,
+               { _("Disabled"), _("MDI child window or main window"), _("MDI child window only"), _("Close main window if there is only one MDI child window") });
+       SetDlgItemComboBoxList(IDC_SINGLE_INSTANCE,
+               { _("Disabled"), _("Allow only one instance to run"), _("Allow only one instance to run and wait for the instance to terminate") });
+       SetDlgItemComboBoxList(IDC_AUTO_RELOAD_MODIFIED_FILES,
+               { _("Disabled"), _("Only on window activated"), _("Immediately") });
 
-       pWnd = (CComboBox*)GetDlgItem(IDC_SINGLE_INSTANCE);
-       ASSERT(pWnd != nullptr);
-
-       for (const auto& item : { _("Disabled"), _("Allow only one instance to run"), _("Allow only one instance to run and wait for the instance to terminate") })
-               pWnd->AddString(item.c_str());
-
-       pWnd->SetCurSel(m_nSingleInstance);
-
-       pWnd = (CComboBox*)GetDlgItem(IDC_AUTO_RELOAD_MODIFIED_FILES);
-       ASSERT(pWnd != nullptr);
-
-       for (const auto& item : { _("Disabled"), _("Only on window activated"), _("Immediately") })
-               pWnd->AddString(item.c_str());
-
-       pWnd->SetCurSel(m_nFileReloadMode);
+       OptionsPanel::OnInitDialog();
 
        m_ctlLangList.SetDroppedWidth(600);
        m_ctlLangList.EnableWindow(FALSE);
index d56c8f0..51b5532 100644 (file)
@@ -140,19 +140,17 @@ BOOL CSelectPluginDlg::OnInitDialog()
 
        if (m_bArgumentsRequired)
        {
-               SetWindowText((_("Specify plugin arguments") + _T(" [") + pluginTypeStr + _T("]")).c_str());
+               SetTitleText(_("Specify plugin arguments") + _T(" [") + pluginTypeStr + _T("]"));
                String args;
-               CString pipeline;
+               String pipeline;
                GetDlgItemText(IDC_PLUGIN_ARGUMENTS, args);
-               m_ctlPluginPipeline.GetWindowText(pipeline);
-               m_strPluginPipeline = pipeline + _T(" ") + args.c_str();
-               m_ctlPluginPipeline.SetWindowText(m_strPluginPipeline.c_str());
-               m_ctlPluginPipeline.SetFocus();
+               GetDlgItemText(IDC_PLUGIN_PIPELINE, pipeline);
+               m_strPluginPipeline = pipeline + _T(" ") + args;
+               SetDlgItemText(IDC_PLUGIN_PIPELINE, m_strPluginPipeline);
+               SetDlgItemFocus(IDC_PLUGIN_PIPELINE);
                return FALSE;
        }
-       CString title;
-       GetWindowText(title);
-       SetWindowText(title + _T(" [") + pluginTypeStr.c_str() + _T("]"));
+       SetTitleText(GetTitleText() + _T(" [") + pluginTypeStr + _T("]"));
 
        return TRUE;  // return TRUE unless you set the focus to a control
                      // EXCEPTION: OCX Property Pages should return FALSE
index 1bfbffa..69f377a 100644 (file)
@@ -37,7 +37,28 @@ public:
 \r
        void SetDlgItemText(unsigned id, const String& text)\r
        {\r
-               return dlg()->SetDlgItemTextW(id, text.c_str());\r
+               dlg()->SetDlgItemTextW(id, text.c_str());\r
+       }\r
+\r
+       void SetDlgItemComboBoxList(unsigned id, const std::initializer_list<String>& list)\r
+       {\r
+               CComboBox * cbo = (CComboBox *)dlg()->GetDlgItem(id);\r
+               if (!cbo)\r
+                       return;\r
+               for (const auto& item : list)\r
+                       cbo->AddString(item.c_str());\r
+       }\r
+\r
+       String GetTitleText()\r
+       {\r
+               CString title;\r
+               dlg()->GetWindowText(title);\r
+               return title.GetString();\r
+       }\r
+\r
+       void SetTitleText(const String& text)\r
+       {\r
+               dlg()->SetWindowText(text.c_str());\r
        }\r
 };\r
 \r
index 90fa1bd..9f732da 100644 (file)
@@ -1041,8 +1041,8 @@ void CWebPageDiffFrame::UpdateWebPageDiffBar()
        bool fitToWindow = m_pWebDiffWindow->GetFitToWindow();
        m_wndWebPageDiffBar.CheckDlgButton(IDC_FITTOWINDOW, fitToWindow);
        m_wndWebPageDiffBar.CheckDlgButton(IDC_SHOWDIFFERENCES, m_pWebDiffWindow->GetShowDifferences());
-       m_wndWebPageDiffBar.GetDlgItem(IDC_WIDTH)->EnableWindow(!fitToWindow);
-       m_wndWebPageDiffBar.GetDlgItem(IDC_HEIGHT)->EnableWindow(!fitToWindow);
+       m_wndWebPageDiffBar.EnableDlgItem(IDC_WIDTH, !fitToWindow);
+       m_wndWebPageDiffBar.EnableDlgItem(IDC_HEIGHT, !fitToWindow);
        SIZE size = m_pWebDiffWindow->GetSize();
        m_wndWebPageDiffBar.SetDlgItemText(IDC_WIDTH, strutils::format(_T("%d"), size.cx));
        m_wndWebPageDiffBar.SetDlgItemText(IDC_HEIGHT, strutils::format(_T("%d"), size.cy));