1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // PatchViewDlg.cpp : implementation file
23 #include "TortoiseProc.h"
24 #include "PatchViewDlg.h"
26 // CPatchViewDlg dialog
28 IMPLEMENT_DYNAMIC(CPatchViewDlg
, CDialog
)
30 CPatchViewDlg::CPatchViewDlg(CWnd
* pParent
/*=nullptr*/)
31 : CDialog(CPatchViewDlg::IDD
, pParent
)
32 , m_ParentDlg(nullptr)
34 , m_bShowFindBar(false)
38 CPatchViewDlg::~CPatchViewDlg()
42 void CPatchViewDlg::DoDataExchange(CDataExchange
* pDX
)
44 CDialog::DoDataExchange(pDX
);
45 DDX_Control(pDX
, IDC_PATCH
, m_ctrlPatchView
);
48 BEGIN_MESSAGE_MAP(CPatchViewDlg
, CDialog
)
52 ON_COMMAND(IDM_SHOWFINDBAR
, OnShowFindBar
)
53 ON_COMMAND(IDM_FINDEXIT
, OnEscape
)
54 ON_COMMAND(IDM_FINDNEXT
, OnFindNext
)
55 ON_COMMAND(IDM_FINDPREV
, OnFindPrev
)
56 ON_REGISTERED_MESSAGE(CFindBar::WM_FINDEXIT
, OnFindExitMessage
)
57 ON_REGISTERED_MESSAGE(CFindBar::WM_FINDNEXT
, OnFindNextMessage
)
58 ON_REGISTERED_MESSAGE(CFindBar::WM_FINDPREV
, OnFindPrevMessage
)
59 ON_REGISTERED_MESSAGE(CFindBar::WM_FINDRESET
, OnFindResetMessage
)
62 // CPatchViewDlg message handlers
64 BOOL
CPatchViewDlg::OnInitDialog()
66 CDialog::OnInitDialog();
68 m_ctrlPatchView
.Init(-1);
70 m_ctrlPatchView
.SetUDiffStyle();
72 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_ACC_PATCHVIEW
));
74 m_FindBar
.Create(IDD_FINDBAR
, this);
76 return TRUE
; // return TRUE unless you set the focus to a control
77 // EXCEPTION: OCX Property Pages should return FALSE
80 void CPatchViewDlg::SetText(const CString
& text
)
82 m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
83 m_ctrlPatchView
.SetText(text
);
84 m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
87 m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
89 m_ctrlPatchView
.GetClientRect(rect
);
90 m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTH
, rect
.Width() - 4);
94 void CPatchViewDlg::ClearView()
99 void CPatchViewDlg::OnSize(UINT nType
, int cx
, int cy
)
101 CDialog::OnSize(nType
, cx
, cy
);
103 if (this->IsWindowVisible())
107 GetDlgItem(IDC_PATCH
)->MoveWindow(0, 0, cx
, cy
);
111 ::SetWindowPos(m_ctrlPatchView
.GetSafeHwnd(), HWND_TOP
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
- 30, SWP_SHOWWINDOW
);
112 ::SetWindowPos(m_FindBar
.GetSafeHwnd(), HWND_TOP
, rect
.left
, rect
.bottom
- 30, rect
.right
- rect
.left
, 30, SWP_SHOWWINDOW
);
116 ::SetWindowPos(m_ctrlPatchView
.GetSafeHwnd(), HWND_TOP
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, SWP_SHOWWINDOW
);
117 m_FindBar
.ShowWindow(SW_HIDE
);
121 m_ctrlPatchView
.GetClientRect(rect2
);
122 m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTH
, rect2
.Width() - 4);
126 void CPatchViewDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
130 m_ParentDlg
->GetPatchViewParentWnd()->GetWindowRect(&parentRect
);
131 if (abs(parentRect
.right
- pRect
->left
) < STICKYSIZE
)
133 int width
= pRect
->right
- pRect
->left
;
134 pRect
->left
= parentRect
.right
;
135 pRect
->right
= pRect
->left
+ width
;
137 CDialog::OnMoving(fwSide
, pRect
);
140 void CPatchViewDlg::OnClose()
143 m_ParentDlg
->TogglePatchView();
146 BOOL
CPatchViewDlg::PreTranslateMessage(MSG
* pMsg
)
150 if (TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
))
153 return __super::PreTranslateMessage(pMsg
);
156 void CPatchViewDlg::OnEscape()
158 if (::IsWindowVisible(m_FindBar
))
163 SendMessage(WM_CLOSE
);
166 void CPatchViewDlg::OnShowFindBar()
168 m_bShowFindBar
= true;
169 m_FindBar
.ShowWindow(SW_SHOW
);
171 GetClientRect(&rect
);
172 ::SetWindowPos(m_ctrlPatchView
.GetSafeHwnd(), HWND_TOP
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
- 30, SWP_SHOWWINDOW
);
173 ::SetWindowPos(m_FindBar
, HWND_TOP
, rect
.left
, rect
.bottom
- 30, rect
.right
- rect
.left
, 30, SWP_SHOWWINDOW
);
174 m_FindBar
.SetFocusTextBox();
175 m_ctrlPatchView
.Call(SCI_SETSELECTIONSTART
, 0);
176 m_ctrlPatchView
.Call(SCI_SETSELECTIONEND
, 0);
177 m_ctrlPatchView
.Call(SCI_SEARCHANCHOR
);
180 void CPatchViewDlg::OnFindNext()
182 m_ctrlPatchView
.Call(SCI_CHARRIGHT
);
183 m_ctrlPatchView
.Call(SCI_SEARCHANCHOR
);
184 m_ctrlPatchView
.Call(SCI_SEARCHNEXT
, m_FindBar
.IsMatchCase() ? SCFIND_MATCHCASE
: 0, (LPARAM
)(LPCSTR
)CUnicodeUtils::GetUTF8(m_FindBar
.GetFindText()));
185 m_ctrlPatchView
.Call(SCI_SCROLLCARET
);
188 void CPatchViewDlg::OnFindPrev()
190 m_ctrlPatchView
.Call(SCI_SEARCHANCHOR
);
191 m_ctrlPatchView
.Call(SCI_SEARCHPREV
, m_FindBar
.IsMatchCase() ? SCFIND_MATCHCASE
: 0, (LPARAM
)(LPCSTR
)CUnicodeUtils::GetUTF8(m_FindBar
.GetFindText()));
192 m_ctrlPatchView
.Call(SCI_SCROLLCARET
);
195 void CPatchViewDlg::OnFindExit()
197 if (!::IsWindowVisible(m_FindBar
))
201 GetClientRect(&rect
);
202 m_bShowFindBar
= false;
203 m_FindBar
.ShowWindow(SW_HIDE
);
204 ::SetWindowPos(m_ctrlPatchView
.GetSafeHwnd(), HWND_TOP
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, SWP_SHOWWINDOW
);
205 m_ctrlPatchView
.SetFocus();
208 void CPatchViewDlg::OnFindReset()
210 m_ctrlPatchView
.Call(SCI_SETSELECTIONSTART
, 0);
211 m_ctrlPatchView
.Call(SCI_SETSELECTIONEND
, 0);
212 m_ctrlPatchView
.Call(SCI_SEARCHANCHOR
);
215 LRESULT
CPatchViewDlg::OnFindNextMessage(WPARAM
, LPARAM
)
221 LRESULT
CPatchViewDlg::OnFindPrevMessage(WPARAM
, LPARAM
)
227 LRESULT
CPatchViewDlg::OnFindExitMessage(WPARAM
, LPARAM
)
233 LRESULT
CPatchViewDlg::OnFindResetMessage(WPARAM
, LPARAM
)