Update OGDF to the latest stable release (v. 2015.05, Baobab)
[TortoiseGit.git] / src / TortoiseUDiff / FindBar.cpp
blob9b1a00f5cb3567537e11f3201024849f2ff932bd
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012-2013, 2015-2016 - TortoiseGit
4 // Copyright (C) 2003-2007, 2012-2013, 2018 - 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 "resource.h"
22 #include "FindBar.h"
23 #include "registry.h"
24 #include <string>
25 #include <Commdlg.h>
26 #include "LoadIconEx.h"
28 CFindBar::CFindBar()
29 : m_hParent(nullptr)
30 , m_hIcon(nullptr)
34 CFindBar::~CFindBar(void)
36 DestroyIcon(m_hIcon);
39 LRESULT CFindBar::DlgFunc(HWND /*hwndDlg*/, UINT uMsg, WPARAM wParam, LPARAM /*lParam*/)
41 switch (uMsg)
43 case WM_INITDIALOG:
45 m_hIcon = LoadIconEx(hResource, MAKEINTRESOURCE(IDI_CANCELNORMAL));
46 SendMessage(GetDlgItem(*this, IDC_FINDEXIT), BM_SETIMAGE, IMAGE_ICON, (LPARAM)m_hIcon);
48 return TRUE;
49 case WM_COMMAND:
50 return DoCommand(LOWORD(wParam), HIWORD(wParam));
51 default:
52 return FALSE;
56 LRESULT CFindBar::DoCommand(int id, int msg)
58 bool bFindPrev = false;
59 switch (id)
61 case IDC_FINDPREV:
62 bFindPrev = true;
63 // fallthrough
64 case IDC_FINDNEXT:
66 DoFind(bFindPrev);
68 break;
69 case IDC_FINDEXIT:
71 ::SendMessage(m_hParent, COMMITMONITOR_FINDEXIT, 0, 0);
73 break;
74 case IDC_FINDTEXT:
76 if (msg == EN_CHANGE)
78 SendMessage(m_hParent, COMMITMONITOR_FINDRESET, 0, 0);
79 DoFind(false);
82 break;
84 return 1;
87 void CFindBar::DoFind(bool bFindPrev)
89 int len = ::GetWindowTextLength(GetDlgItem(*this, IDC_FINDTEXT));
90 auto findtext = std::make_unique<TCHAR[]>(len + 1);
91 if (!::GetWindowText(GetDlgItem(*this, IDC_FINDTEXT), findtext.get(), len + 1))
92 return;
93 std::wstring ft = std::wstring(findtext.get());
94 const bool bCaseSensitive = !!SendMessage(GetDlgItem(*this, IDC_MATCHCASECHECK), BM_GETCHECK, 0, 0);
95 const UINT message = bFindPrev ? COMMITMONITOR_FINDMSGPREV : COMMITMONITOR_FINDMSGNEXT;
96 ::SendMessage(m_hParent, message, (WPARAM)bCaseSensitive, (LPARAM)ft.c_str());