High DPI optimizations
[TortoiseGit.git] / src / TortoiseGitBlame / OutputWnd.cpp
blobd73756a3e8e026344c8c28eea34f4f735250791a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2016, 2018 - 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.
21 #include "stdafx.h"
23 #include "OutputWnd.h"
24 #include "Resource.h"
25 #include "MainFrm.h"
26 #include "TortoiseGitBlameDoc.h"
27 #include "TortoiseGitBlameView.h"
29 #ifdef _DEBUG
30 #define new DEBUG_NEW
31 #undef THIS_FILE
32 static char THIS_FILE[] = __FILE__;
33 #endif
35 /////////////////////////////////////////////////////////////////////////////
36 // COutputBar
38 COutputWnd::COutputWnd()
42 COutputWnd::~COutputWnd()
46 IMPLEMENT_DYNAMIC(COutputWnd, CDockablePane)
48 BEGIN_MESSAGE_MAP(COutputWnd, CDockablePane)
49 ON_WM_CREATE()
50 ON_WM_SIZE()
51 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOG, OnLvnItemchangedLoglist)
52 END_MESSAGE_MAP()
54 int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
56 if (CDockablePane::OnCreate(lpCreateStruct) == -1)
57 return -1;
59 NONCLIENTMETRICS metrics = { 0 };
60 metrics.cbSize = sizeof(NONCLIENTMETRICS);
61 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, FALSE);
62 LOGFONT lf = { 0 };
63 memcpy_s(&lf, sizeof(LOGFONT), &metrics.lfMessageFont, sizeof(LOGFONT));
64 m_Font.CreateFontIndirect(&lf);
66 CRect rectDummy;
67 rectDummy.SetRectEmpty();
69 // Create output panes:
70 const DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
72 if (!m_LogList.Create(dwStyle, rectDummy, this, IDC_LOG))
74 TRACE0("Failed to create output windows\n");
75 return -1; // fail to create
78 // for some unknown reason, the SetExtendedStyle in OnCreate/PreSubclassWindow is not working here
79 m_LogList.SetStyle();
81 m_LogList.SetFont(&m_Font);
83 m_Gravatar.Create(L"", WS_CHILD | WS_VISIBLE, rectDummy, this);
84 bool bEnableGravatar = !!CRegDWORD(L"Software\\TortoiseGit\\EnableGravatar", FALSE);
85 m_Gravatar.EnableGravatar(bEnableGravatar);
86 if (bEnableGravatar)
87 m_Gravatar.Init();
89 CString strTabName;
90 BOOL bNameValid;
92 // Attach list windows to tab:
93 bNameValid = strTabName.LoadString(IDS_GIT_LOG_TAB);
94 ASSERT(bNameValid);
96 m_LogList.m_IsIDReplaceAction=TRUE;
97 m_LogList.DeleteAllItems();
98 m_LogList.m_ColumnRegKey = L"Blame";
99 m_LogList.InsertGitColumn();
101 m_LogList.hideUnimplementedCommands();
103 this->SetWindowTextW(CString(MAKEINTRESOURCE(IDS_GIT_LOG_TAB)));
104 return 0;
107 void COutputWnd::OnSize(UINT nType, int cx, int cy)
109 CDockablePane::OnSize(nType, cx, cy);
111 // Tab control should cover the whole client area:
112 if (m_Gravatar.IsGravatarEnabled())
114 m_LogList.SetWindowPos(nullptr, -1, -1, cx - 80, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
115 m_Gravatar.SetWindowPos(nullptr, cx - 80, 0, 80, 80, SWP_NOACTIVATE | SWP_NOZORDER);
116 return;
118 m_LogList.SetWindowPos(nullptr, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
121 int COutputWnd::LoadHistory(CString filename, CString revision, bool follow)
123 CTGitPath path;
124 path.SetFromGit(filename);
126 m_LogList.Clear();
127 m_LogList.ShowGraphColumn(!follow);
128 if (m_LogList.FillGitLog(&path, &revision, follow ? CGit::LOG_INFO_FOLLOW : 0))
129 return -1;
130 m_LogList.UpdateProjectProperties();
131 return 0;
134 int COutputWnd::LoadHistory(std::unordered_set<CGitHash>& hashes)
136 m_LogList.Clear();
137 m_LogList.ShowGraphColumn(false);
138 if (m_LogList.FillGitLog(hashes))
139 return -1;
140 m_LogList.UpdateProjectProperties();
141 return 0;
144 void COutputWnd::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
146 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
147 *pResult = 0;
149 //if (this->IsThreadRunning())
150 if (pNMLV->iItem >= 0)
152 if (pNMLV->iSubItem != 0)
153 return;
155 if (pNMLV->uNewState & LVIS_SELECTED)
157 CMainFrame *pMain=DYNAMIC_DOWNCAST(CMainFrame,AfxGetApp()->GetMainWnd());
158 POSITION pos=pMain->GetActiveDocument()->GetFirstViewPosition();
159 CTortoiseGitBlameView *pView=DYNAMIC_DOWNCAST(CTortoiseGitBlameView,pMain->GetActiveDocument()->GetNextView(pos));
160 pView->FocusOn(&this->m_LogList.m_logEntries.GetGitRevAt(pNMLV->iItem));
161 m_Gravatar.LoadGravatar(m_LogList.m_logEntries.GetGitRevAt(pNMLV->iItem).GetAuthorEmail());
165 /////////////////////////////////////////////////////////////////////////////
166 // COutputList1
168 COutputList::COutputList()
172 COutputList::~COutputList()
176 BEGIN_MESSAGE_MAP(COutputList, CListBox)
177 ON_WM_CONTEXTMENU()
178 ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)
179 ON_WM_WINDOWPOSCHANGING()
180 END_MESSAGE_MAP()
181 /////////////////////////////////////////////////////////////////////////////
182 // COutputList message handlers
184 void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
186 CMenu menu;
187 menu.LoadMenu(IDR_OUTPUT_POPUP);
189 CMenu* pSumMenu = menu.GetSubMenu(0);
191 if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
193 CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
195 if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
196 return;
198 ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
199 UpdateDialogControls(this, FALSE);
202 SetFocus();
205 void COutputList::OnViewOutput()
207 CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());
208 CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
210 if (pMainFrame && pParentBar)
212 pMainFrame->SetFocus();
213 pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);
214 pMainFrame->RecalcLayout();