OSDN Git Service

crystaledit: Use GetProfile*()/WriteProfile*() to read and write the registry wheneve...
[winmerge-jp/winmerge-jp.git] / Src / FilepathEdit.cpp
index a50b74e..10c19c1 100644 (file)
@@ -2,21 +2,7 @@
 //    WinMerge:  an interactive diff/merge utility
 //    Copyright (C) 1997-2000  Thingamahoochie Software
 //    Author: Dean Grimm
-//
-//    This program is free software; you can redistribute it and/or modify
-//    it under the terms of the GNU General Public License as published by
-//    the Free Software Foundation; either version 2 of the License, or
-//    (at your option) any later version.
-//
-//    This program is distributed in the hope that it will be useful,
-//    but WITHOUT ANY WARRANTY; without even the implied warranty of
-//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//    GNU General Public License for more details.
-//
-//    You should have received a copy of the GNU General Public License
-//    along with this program; if not, write to the Free Software
-//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
+//    SPDX-License-Identifier: GPL-2.0-or-later
 /////////////////////////////////////////////////////////////////////////////
 /** 
  * @file  FilePathEdit.cpp
@@ -42,6 +28,7 @@ BEGIN_MESSAGE_MAP(CFilepathEdit, CEdit)
        ON_WM_CONTEXTMENU()
        ON_WM_CTLCOLOR_REFLECT()
        ON_WM_NCPAINT()
+       ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
 END_MESSAGE_MAP()
 
 
@@ -63,7 +50,7 @@ static int FormatFilePathForDisplayWidth(CDC * pDC, int maxWidth, String & sFile
        size_t iBegin = 0;
        int nLines = 1;
        
-       while (1)
+       while (true)
        {
                String line;
 
@@ -111,7 +98,7 @@ static int FormatFilePathForDisplayWidth(CDC * pDC, int maxWidth, String & sFile
 CFilepathEdit::CFilepathEdit()
  : m_crBackGnd(RGB(255, 255, 255))
  , m_crText(RGB(0,0,0))
- , m_bActive(FALSE)
+ , m_bActive(false)
 {
 }
 
@@ -119,24 +106,15 @@ CFilepathEdit::CFilepathEdit()
  * @brief Subclass the control.
  * @param [in] nID ID of the control to subclass.
  * @param [in] pParent Parent control of the control to subclass.
- * @return TRUE if succeeded, FALSE otherwise.
+ * @return `true` if succeeded, `false` otherwise.
  */
-BOOL CFilepathEdit::SubClassEdit(UINT nID, CWnd* pParent)
+bool CFilepathEdit::SubClassEdit(UINT nID, CWnd* pParent)
 {
-       m_bActive = FALSE;
+       m_bActive = false;
        return SubclassDlgItem(nID, pParent);
 };
 
 /**
- * @brief Return the control's original text.
- * @return Control's original text.
- */
-void CFilepathEdit::GetOriginalText(String& rString) const
-{              
-       rString = m_sOriginalText;
-}
-
-/**
  * @brief Set the text to show in the control.
  * This function sets the text (original text) to show in the control.
  * The control may modify the text for displaying in the GUI.
@@ -249,7 +227,7 @@ void CFilepathEdit::OnContextMenu(CWnd*, CPoint point)
                theApp.TranslateMenu(menu.m_hMenu);
 
                BCMenu* pPopup = static_cast<BCMenu *>(menu.GetSubMenu(0));
-               ASSERT(pPopup != NULL);
+               ASSERT(pPopup != nullptr);
 
                DWORD sel = GetSel();
                if (HIWORD(sel) == LOWORD(sel))
@@ -314,25 +292,46 @@ void CFilepathEdit::OnNcPaint()
        GetWindowRect(rect);
        rect.OffsetRect(-rect.TopLeft());
        dc.FillSolidRect(CRect(rect.left, rect.top, rect.left + margin, rect.bottom), GetDarkenColor(m_crBackGnd, 0.98));
-       dc.FillSolidRect(CRect(rect.left, rect.top, rect.left + 1, rect.bottom), GetDarkenColor(m_crBackGnd, 0.90));
+       dc.FillSolidRect(CRect(rect.left, rect.top, rect.left + 1, rect.bottom), GetDarkenColor(m_crBackGnd, 0.96));
        dc.FillSolidRect(CRect(rect.right - margin, rect.top, rect.right, rect.bottom), m_crBackGnd);
        dc.FillSolidRect(CRect(rect.left + 1, rect.top, rect.right, rect.top + margin), GetDarkenColor(m_crBackGnd, 0.98));
-       dc.FillSolidRect(CRect(rect.left, rect.top, rect.right, rect.top + 1), GetDarkenColor(m_crBackGnd, 0.90));
+       dc.FillSolidRect(CRect(rect.left, rect.top, rect.right, rect.top + 1), GetDarkenColor(m_crBackGnd, 0.96));
        dc.FillSolidRect(CRect(rect.left + margin, rect.bottom - margin, rect.right, rect.bottom), m_crBackGnd);
 }
 
+void CFilepathEdit::OnEditCopy()
+{
+       int nStartChar, nEndChar;
+       GetSel(nStartChar, nEndChar);
+       if (nStartChar == nEndChar)
+               SetSel(0, -1);
+       Copy();
+       if (nStartChar == nEndChar)
+               SetSel(nStartChar, nEndChar);
+}
+
+BOOL CFilepathEdit::PreTranslateMessage(MSG *pMsg)
+{
+       if (pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST)
+       {
+               if (::TranslateAccelerator (m_hWnd, static_cast<CFrameWnd *>(AfxGetMainWnd())->GetDefaultAccelerator(), pMsg))
+                       return TRUE;
+       }
+       return CEdit::PreTranslateMessage(pMsg);
+}
+
 /**
  * @brief Set the control to look active/inactive.
  * This function sets control to look like an active control. We don't
  * have real focus on this control, but editor pane below it. However
  * for user this active look informs which editor pane is active.
- * @param [in] bActive If TRUE set control look like active control.
+ * @param [in] bActive If `true` set control look like active control.
  */
 void CFilepathEdit::SetActive(bool bActive)
 {
        m_bActive = bActive;
 
-       if (m_hWnd == NULL)
+       if (m_hWnd == nullptr)
                return;
 
        CRect rcWnd;
@@ -348,7 +347,7 @@ void CFilepathEdit::SetActive(bool bActive)
                SetTextColor(::GetSysColor(COLOR_INACTIVECAPTIONTEXT));
                SetBackColor(::GetSysColor(COLOR_INACTIVECAPTION));
        }
-       RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
+       RedrawWindow(nullptr, nullptr, RDW_FRAME | RDW_INVALIDATE);
 }
 
 /**
@@ -362,7 +361,7 @@ void CFilepathEdit::SetActive(bool bActive)
 HBRUSH CFilepathEdit::CtlColor(CDC* pDC, UINT nCtlColor) 
 {
        UNUSED_ALWAYS(nCtlColor);
-       // Return a non-NULL brush if the parent's 
+       // Return a non-`nullptr` brush if the parent's 
        //handler should not be called
 
        //set text color