Sync translations with Transifex
[TortoiseGit.git] / src / Utils / MiscUI / RegexEdit.cpp
blob363e17972cceaf85a0604cb60c04f83b7f99b8e5
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012 - TortoiseGit
4 // Copyright (C) 2011 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "RegexEdit.h"
22 #include <regex>
24 // CRegexEdit
26 IMPLEMENT_DYNAMIC(CRegexEdit, CEdit)
27 CRegexEdit::CRegexEdit()
29 m_bValid = true;
32 CRegexEdit::~CRegexEdit()
36 BEGIN_MESSAGE_MAP(CRegexEdit, CEdit)
37 ON_WM_CTLCOLOR_REFLECT()
38 END_MESSAGE_MAP()
40 HBRUSH CRegexEdit::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
42 bool oldState = m_bValid;
43 // check if the regex is valid
44 m_bValid = true;
45 try
47 CString sRegex;
48 GetWindowText(sRegex);
49 const std::tr1::wregex regMatch(sRegex, std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
51 catch (std::exception)
53 m_bValid = false;
56 if (!m_bValid)
58 pDC->SetBkColor(GetSysColor(COLOR_3DFACE) - RGB(0,20,20));
59 if (m_invalidBkgnd.GetSafeHandle() == NULL)
60 m_invalidBkgnd.CreateSolidBrush(GetSysColor(COLOR_3DFACE) - RGB(0,20,20));
61 return (HBRUSH)m_invalidBkgnd.GetSafeHandle();
63 else if (!oldState)
64 this->Invalidate();
66 return NULL;