Remove unused variables
[TortoiseGit.git] / src / TortoiseProc / RevisionGraph / RevisionGraphWnd.cpp
bloba8ebc7f10ba04989fcf4bd2129a708c90d1a886e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2012, 2015 - TortoiseSVN
4 // Copyright (C) 2012-2016 - TortoiseGit
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 "TortoiseProc.h"
22 #include "Revisiongraphwnd.h"
23 #include "MessageBox.h"
24 #include "Git.h"
25 #include "AppUtils.h"
26 #include "PathUtils.h"
27 #include "StringUtils.h"
28 #include "TempFile.h"
29 #include "UnicodeUtils.h"
30 #include "TGitPath.h"
31 #include "RevisionGraphDlg.h"
32 #include "BrowseFolder.h"
33 #include "GitProgressDlg.h"
34 #include "ChangedDlg.h"
35 //#include "RevisionGraph/StandardLayout.h"
36 //#include "RevisionGraph/UpsideDownLayout.h"
37 #include "FormatMessageWrapper.h"
38 #include "GitRevLoglist.h"
40 #pragma warning(push)
41 #pragma warning(disable: 4100) // unreferenced formal parameter
42 #include <ogdf/planarity/PlanarizationLayout.h>
43 #include <ogdf/planarity/VariableEmbeddingInserter.h>
44 #include <ogdf/planarity/FastPlanarSubgraph.h>
45 #include <ogdf/orthogonal/OrthoLayout.h>
46 #include <ogdf/planarity/EmbedderMinDepthMaxFaceLayers.h>
47 #pragma warning(pop)
49 #ifdef _DEBUG
50 #define new DEBUG_NEW
51 #undef THIS_FILE
52 static char THIS_FILE[] = __FILE__;
53 #endif
55 using namespace Gdiplus;
56 using namespace ogdf;
58 enum RevisionGraphContextMenuCommands
60 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
61 GROUP_MASK = 0xff00,
62 ID_SHOWLOG = 1,
63 ID_CFM = 2,
64 ID_BROWSEREPO,
65 ID_COMPAREREVS = 0x100,
66 ID_COMPAREHEADS,
67 ID_COMPAREWT,
68 ID_UNIDIFFREVS,
69 ID_UNIDIFFHEADS,
70 ID_MERGETO = 0x300,
71 ID_UPDATE,
72 ID_SWITCHTOHEAD,
73 ID_SWITCH,
74 ID_COPYREFS = 0x400,
75 ID_EXPAND_ALL = 0x500,
76 ID_JOIN_ALL,
77 ID_GRAPH_EXPANDCOLLAPSE_ABOVE = 0x600,
78 ID_GRAPH_EXPANDCOLLAPSE_RIGHT,
79 ID_GRAPH_EXPANDCOLLAPSE_BELOW,
80 ID_GRAPH_SPLITJOIN_ABOVE,
81 ID_GRAPH_SPLITJOIN_RIGHT,
82 ID_GRAPH_SPLITJOIN_BELOW,
85 CRevisionGraphWnd::CRevisionGraphWnd()
86 : CWnd()
87 , m_SelectedEntry1(nullptr)
88 , m_SelectedEntry2(nullptr)
89 , m_HeadNode(nullptr)
90 , m_pDlgTip(nullptr)
91 , m_nFontSize(12)
92 , m_bTweakTrunkColors(true)
93 , m_bTweakTagsColors(true)
94 , m_fZoomFactor(DEFAULT_ZOOM)
95 , m_ptRubberEnd(0,0)
96 , m_ptMoveCanvas(0,0)
97 , m_bShowOverview(false)
98 , m_parent(nullptr)
99 , m_hoverIndex(nullptr)
100 , m_hoverGlyphs (0)
101 , m_tooltipIndex(nullptr)
102 , m_showHoverGlyphs (false)
103 , m_bIsCanvasMove(false)
104 , m_previewWidth(0)
105 , m_previewHeight(0)
106 , m_previewZoom(1)
107 , m_ullTicks(0)
108 , m_logEntries(&m_LogCache)
109 , m_bCurrentBranch(false)
110 , m_bLocalBranches(FALSE)
112 memset(&m_lfBaseFont, 0, sizeof(LOGFONT));
113 std::fill_n(m_apFonts, MAXFONTS, nullptr);
115 WNDCLASS wndcls;
116 HINSTANCE hInst = AfxGetInstanceHandle();
117 #define REVGRAPH_CLASSNAME L"Revgraph_windowclass"
118 if (!(::GetClassInfo(hInst, REVGRAPH_CLASSNAME, &wndcls)))
120 // otherwise we need to register a new class
121 wndcls.style = CS_DBLCLKS | CS_OWNDC;
122 wndcls.lpfnWndProc = ::DefWindowProc;
123 wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
124 wndcls.hInstance = hInst;
125 wndcls.hIcon = nullptr;
126 wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
127 wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
128 wndcls.lpszMenuName = nullptr;
129 wndcls.lpszClassName = REVGRAPH_CLASSNAME;
131 RegisterClass(&wndcls);
134 m_bTweakTrunkColors = CRegDWORD(L"Software\\TortoiseGit\\RevisionGraph\\TweakTrunkColors", TRUE) != FALSE;
135 m_bTweakTagsColors = CRegDWORD(L"Software\\TortoiseGit\\RevisionGraph\\TweakTagsColors", TRUE) != FALSE;
136 m_szTip[0] = '\0';
137 m_wszTip[0] = L'\0';
139 m_GraphAttr.init(this->m_Graph, ogdf::GraphAttributes::nodeGraphics | ogdf::GraphAttributes::edgeGraphics |
140 ogdf:: GraphAttributes::nodeLabel | ogdf::GraphAttributes::nodeColor |
141 ogdf::GraphAttributes::edgeColor | ogdf::GraphAttributes::edgeStyle |
142 ogdf::GraphAttributes::nodeStyle | ogdf::GraphAttributes::nodeTemplate);
144 m_SugiyamLayout.setRanking(::new ogdf::OptimalRanking());
145 m_SugiyamLayout.setCrossMin(::new ogdf::MedianHeuristic());
147 double pi = 3.1415926;
148 m_ArrowCos = cos(pi/8);
149 m_ArrowSin = sin(pi/8);
150 this->m_ArrowSize = 8;
151 #if 0
152 ogdf::node one = this->m_Graph.newNode();
153 ogdf::node two = this->m_Graph.newNode();
154 ogdf::node three = this->m_Graph.newNode();
155 ogdf::node four = this->m_Graph.newNode();
158 m_GraphAttr.width(one)=100;
159 m_GraphAttr.height(one)=200;
160 m_GraphAttr.width(two)=100;
161 m_GraphAttr.height(two)=100;
162 m_GraphAttr.width(three)=100;
163 m_GraphAttr.height(three)=20;
164 m_GraphAttr.width(four)=100;
165 m_GraphAttr.height(four)=20;
167 m_GraphAttr.labelNode(one)="One";
168 m_GraphAttr.labelNode(two)="Two";
169 m_GraphAttr.labelNode(three)="three";
171 this->m_Graph.newEdge(one, two);
172 this->m_Graph.newEdge(one, three);
173 this->m_Graph.newEdge(two, four);
174 this->m_Graph.newEdge(three, four);
176 #endif
177 FastHierarchyLayout *pOHL = ::new FastHierarchyLayout;
178 //It will auto delte when m_SugiyamLayout destory
180 pOHL->layerDistance(30.0);
181 pOHL->nodeDistance(25.0);
183 m_SugiyamLayout.setLayout(pOHL);
185 #if 0
186 //this->m_OHL.layerDistance(30.0);
187 //this->m_OHL.nodeDistance(25.0);
188 //this->m_OHL.weightBalancing(0.8);
189 m_SugiyamLayout.setLayout(&m_OHL);
190 m_SugiyamLayout.call(m_GraphAttr);
191 #endif
192 #if 0
193 PlanarizationLayout pl;
195 FastPlanarSubgraph *ps = ::new FastPlanarSubgraph;
196 ps->runs(100);
197 VariableEmbeddingInserter *ves = ::new VariableEmbeddingInserter;
198 ves->removeReinsert(EdgeInsertionModule::rrAll);
199 pl.setSubgraph(ps);
200 pl.setInserter(ves);
202 EmbedderMinDepthMaxFaceLayers *emb = ::new EmbedderMinDepthMaxFaceLayers;
203 pl.setEmbedder(emb);
205 OrthoLayout *ol =::new OrthoLayout;
206 ol->separation(20.0);
207 ol->cOverhang(0.4);
208 ol->setOptions(2+4);
209 ol->preferedDir(OrthoDir::odEast);
210 pl.setPlanarLayouter(ol);
212 pl.call(m_GraphAttr);
214 node v;
215 forall_nodes(v,m_Graph) {
216 TRACE(L"node x %f y %f %f %f\n",/* m_GraphAttr.idNode(v), */
217 m_GraphAttr.x(v),
218 m_GraphAttr.y(v),
219 m_GraphAttr.width(v),
220 m_GraphAttr.height(v)
224 edge e;
225 forall_edges(e, m_Graph)
227 // get connection and point position
228 const DPolyline &dpl = this->m_GraphAttr.bends(e);
230 ListConstIterator<DPoint> it;
231 for(it = dpl.begin(); it.valid(); ++it)
233 TRACE(L"edge %f %f\n", (*it).m_x, (*it).m_y);
236 m_GraphAttr.writeGML("test.gml");
237 #endif
240 CRevisionGraphWnd::~CRevisionGraphWnd()
242 for (int i = 0; i < MAXFONTS; ++i)
244 if (m_apFonts[i])
246 m_apFonts[i]->DeleteObject();
247 delete m_apFonts[i];
249 m_apFonts[i] = nullptr;
251 delete m_pDlgTip;
252 m_Graph.clear();
255 void CRevisionGraphWnd::DoDataExchange(CDataExchange* pDX)
257 CWnd::DoDataExchange(pDX);
261 BEGIN_MESSAGE_MAP(CRevisionGraphWnd, CWnd)
262 ON_WM_PAINT()
263 ON_WM_ERASEBKGND()
264 ON_WM_HSCROLL()
265 ON_WM_VSCROLL()
266 ON_WM_SIZE()
267 ON_WM_LBUTTONDOWN()
268 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
269 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
270 ON_WM_MOUSEWHEEL()
271 ON_WM_MOUSEHWHEEL()
272 ON_WM_CONTEXTMENU()
273 ON_WM_MOUSEMOVE()
274 ON_WM_LBUTTONUP()
275 ON_WM_SETCURSOR()
276 ON_WM_TIMER()
277 ON_MESSAGE(WM_WORKERTHREADDONE,OnWorkerThreadDone)
278 ON_WM_CAPTURECHANGED()
279 END_MESSAGE_MAP()
281 void CRevisionGraphWnd::Init(CWnd * pParent, LPRECT rect)
283 WNDCLASS wndcls;
284 HINSTANCE hInst = AfxGetInstanceHandle();
285 #define REVGRAPH_CLASSNAME L"Revgraph_windowclass"
286 if (!(::GetClassInfo(hInst, REVGRAPH_CLASSNAME, &wndcls)))
288 // otherwise we need to register a new class
289 wndcls.style = CS_DBLCLKS | CS_OWNDC;
290 wndcls.lpfnWndProc = ::DefWindowProc;
291 wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
292 wndcls.hInstance = hInst;
293 wndcls.hIcon = nullptr;
294 wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
295 wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
296 wndcls.lpszMenuName = nullptr;
297 wndcls.lpszClassName = REVGRAPH_CLASSNAME;
299 RegisterClass(&wndcls);
302 if (!IsWindow(m_hWnd))
303 CreateEx(WS_EX_CLIENTEDGE, REVGRAPH_CLASSNAME, L"RevGraph", WS_CHILD|WS_VISIBLE|WS_TABSTOP, *rect, pParent, 0);
304 m_pDlgTip = new CToolTipCtrl;
305 if(!m_pDlgTip->Create(this))
307 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Unable to add tooltip!\n");
309 EnableToolTips();
311 memset(&m_lfBaseFont, 0, sizeof(m_lfBaseFont));
312 m_lfBaseFont.lfHeight = 0;
313 m_lfBaseFont.lfWeight = FW_NORMAL;
314 m_lfBaseFont.lfItalic = FALSE;
315 m_lfBaseFont.lfCharSet = DEFAULT_CHARSET;
316 m_lfBaseFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
317 m_lfBaseFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
318 m_lfBaseFont.lfQuality = DEFAULT_QUALITY;
319 m_lfBaseFont.lfPitchAndFamily = DEFAULT_PITCH;
321 m_ullTicks = GetTickCount64();
323 m_parent = dynamic_cast<CRevisionGraphDlg*>(pParent);
326 CPoint CRevisionGraphWnd::GetLogCoordinates (CPoint point) const
328 // translate point into logical coordinates
330 int nVScrollPos = GetScrollPos(SB_VERT);
331 int nHScrollPos = GetScrollPos(SB_HORZ);
333 return CPoint ( (int)((point.x + nHScrollPos) / m_fZoomFactor)
334 , (int)((point.y + nVScrollPos) / m_fZoomFactor));
337 node CRevisionGraphWnd::GetHitNode (CPoint point, CSize /*border*/) const
339 #if 0
340 // any nodes at all?
342 CSyncPointer<const ILayoutNodeList> nodeList (m_state.GetNodes());
343 if (!nodeList)
344 return index_t(NO_INDEX);
346 // search the nodes for one at that grid position
348 return nodeList->GetAt (GetLogCoordinates (point), border);
349 #endif
351 node v;
352 forall_nodes(v,m_Graph)
354 RectF noderect (GetNodeRect (v, CPoint(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT))));
355 if(point.x>noderect.X && point.x <(noderect.X+noderect.Width) &&
356 point.y>noderect.Y && point.y <(noderect.Y+noderect.Height))
358 return v;
361 return nullptr;
364 DWORD CRevisionGraphWnd::GetHoverGlyphs (CPoint /*point*/) const
366 // if there is no layout, there will be no nodes,
367 // hence, no glyphs
368 DWORD result = 0;
369 #if 0
370 CSyncPointer<const ILayoutNodeList> nodeList (m_state.GetNodes());
371 if (!nodeList)
372 return 0;
374 // get node at point or node that is close enough
375 // so that point may hit a glyph area
377 index_t nodeIndex = GetHitNode(point);
378 if (nodeIndex == NO_INDEX)
379 nodeIndex = GetHitNode(point, CSize (GLYPH_SIZE, GLYPH_SIZE / 2));
381 if (nodeIndex >= nodeList->GetCount())
382 return 0;
384 ILayoutNodeList::SNode node = nodeList->GetNode (nodeIndex);
385 const CVisibleGraphNode* base = node.node;
387 // what glyphs should be shown depending on position of point
388 // relative to the node rect?
390 CPoint logCoordinates = GetLogCoordinates (point);
391 CRect r = node.rect;
392 CPoint center = r.CenterPoint();
394 CRect rightGlyphArea ( r.right - GLYPH_SIZE, center.y - GLYPH_SIZE / 2
395 , r.right + GLYPH_SIZE, center.y + GLYPH_SIZE / 2);
396 CRect topGlyphArea ( center.x - GLYPH_SIZE, r.top - GLYPH_SIZE / 2
397 , center.x + GLYPH_SIZE, r.top + GLYPH_SIZE / 2);
398 CRect bottomGlyphArea ( center.x - GLYPH_SIZE, r.bottom - GLYPH_SIZE / 2
399 , center.x + GLYPH_SIZE, r.bottom + GLYPH_SIZE / 2);
401 bool upsideDown
402 = m_state.GetOptions()->GetOption<CUpsideDownLayout>()->IsActive();
404 if (upsideDown)
406 std::swap (topGlyphArea.top, bottomGlyphArea.top);
407 std::swap (topGlyphArea.bottom, bottomGlyphArea.bottom);
411 if (rightGlyphArea.PtInRect (logCoordinates))
412 result = base->GetFirstCopyTarget()
413 ? CGraphNodeStates::COLLAPSED_RIGHT | CGraphNodeStates::SPLIT_RIGHT
414 : 0;
416 if (topGlyphArea.PtInRect (logCoordinates))
417 result = base->GetSource()
418 ? CGraphNodeStates::COLLAPSED_ABOVE | CGraphNodeStates::SPLIT_ABOVE
419 : 0;
421 if (bottomGlyphArea.PtInRect (logCoordinates))
422 result = base->GetNext()
423 ? CGraphNodeStates::COLLAPSED_BELOW | CGraphNodeStates::SPLIT_BELOW
424 : 0;
426 // if some nodes have already been split, don't allow collapsing etc.
428 CSyncPointer<const CGraphNodeStates> nodeStates (m_state.GetNodeStates());
429 if (result & nodeStates->GetFlags (base))
430 result = 0;
431 #endif
432 return result;
434 #if 0
435 const CRevisionGraphState::SVisibleGlyph* CRevisionGraphWnd::GetHitGlyph (CPoint point) const
437 float glyphSize = GLYPH_SIZE * m_fZoomFactor;
439 CSyncPointer<const CRevisionGraphState::TVisibleGlyphs>
440 visibleGlyphs (m_state.GetVisibleGlyphs());
442 for (size_t i = 0, count = visibleGlyphs->size(); i < count; ++i)
444 const CRevisionGraphState::SVisibleGlyph* entry = &(*visibleGlyphs)[i];
446 float xRel = point.x - entry->leftTop.X;
447 float yRel = point.y - entry->leftTop.Y;
449 if ( (xRel >= 0) && (xRel < glyphSize)
450 && (yRel >= 0) && (yRel < glyphSize))
452 return entry;
456 return nullptr;
458 #endif
459 void CRevisionGraphWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
461 SCROLLINFO sinfo = {0};
462 sinfo.cbSize = sizeof(SCROLLINFO);
463 GetScrollInfo(SB_HORZ, &sinfo);
465 // Determine the new position of scroll box.
466 switch (nSBCode)
468 case SB_LEFT: // Scroll to far left.
469 sinfo.nPos = sinfo.nMin;
470 break;
471 case SB_RIGHT: // Scroll to far right.
472 sinfo.nPos = sinfo.nMax;
473 break;
474 case SB_ENDSCROLL: // End scroll.
475 break;
476 case SB_LINELEFT: // Scroll left.
477 if (sinfo.nPos > sinfo.nMin)
478 sinfo.nPos--;
479 break;
480 case SB_LINERIGHT: // Scroll right.
481 if (sinfo.nPos < sinfo.nMax)
482 ++sinfo.nPos;
483 break;
484 case SB_PAGELEFT: // Scroll one page left.
486 if (sinfo.nPos > sinfo.nMin)
487 sinfo.nPos = max(sinfo.nMin, sinfo.nPos - (int) sinfo.nPage);
489 break;
490 case SB_PAGERIGHT: // Scroll one page right.
492 if (sinfo.nPos < sinfo.nMax)
493 sinfo.nPos = min(sinfo.nMax, sinfo.nPos + (int) sinfo.nPage);
495 break;
496 case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
497 sinfo.nPos = sinfo.nTrackPos; // of the scroll box at the end of the drag operation.
498 break;
499 case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
500 sinfo.nPos = sinfo.nTrackPos; // position that the scroll box has been dragged to.
501 break;
503 SetScrollInfo(SB_HORZ, &sinfo);
504 Invalidate (FALSE);
505 __super::OnHScroll(nSBCode, nPos, pScrollBar);
508 void CRevisionGraphWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
510 SCROLLINFO sinfo = {0};
511 sinfo.cbSize = sizeof(SCROLLINFO);
512 GetScrollInfo(SB_VERT, &sinfo);
514 // Determine the new position of scroll box.
515 switch (nSBCode)
517 case SB_LEFT: // Scroll to far left.
518 sinfo.nPos = sinfo.nMin;
519 break;
520 case SB_RIGHT: // Scroll to far right.
521 sinfo.nPos = sinfo.nMax;
522 break;
523 case SB_ENDSCROLL: // End scroll.
524 break;
525 case SB_LINELEFT: // Scroll left.
526 if (sinfo.nPos > sinfo.nMin)
527 sinfo.nPos--;
528 break;
529 case SB_LINERIGHT: // Scroll right.
530 if (sinfo.nPos < sinfo.nMax)
531 ++sinfo.nPos;
532 break;
533 case SB_PAGELEFT: // Scroll one page left.
535 if (sinfo.nPos > sinfo.nMin)
536 sinfo.nPos = max(sinfo.nMin, sinfo.nPos - (int) sinfo.nPage);
538 break;
539 case SB_PAGERIGHT: // Scroll one page right.
541 if (sinfo.nPos < sinfo.nMax)
542 sinfo.nPos = min(sinfo.nMax, sinfo.nPos + (int) sinfo.nPage);
544 break;
545 case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
546 sinfo.nPos = sinfo.nTrackPos; // of the scroll box at the end of the drag operation.
547 break;
548 case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
549 sinfo.nPos = sinfo.nTrackPos; // position that the scroll box has been dragged to.
550 break;
552 SetScrollInfo(SB_VERT, &sinfo);
553 Invalidate(FALSE);
554 __super::OnVScroll(nSBCode, nPos, pScrollBar);
557 void CRevisionGraphWnd::OnSize(UINT nType, int cx, int cy)
559 __super::OnSize(nType, cx, cy);
560 SetScrollbars(GetScrollPos(SB_VERT), GetScrollPos(SB_HORZ));
561 Invalidate(FALSE);
564 void CRevisionGraphWnd::OnLButtonDown(UINT nFlags, CPoint point)
566 if (IsUpdateJobRunning())
567 return __super::OnLButtonDown(nFlags, point);
569 // CSyncPointer<const ILayoutNodeList> nodeList (m_state.GetNodes());
571 SetFocus();
572 bool bHit = false;
573 bool bControl = !!(GetKeyState(VK_CONTROL)&0x8000);
574 bool bOverview = m_bShowOverview && m_OverviewRect.PtInRect(point);
575 if (! bOverview)
577 #if 0
578 const CRevisionGraphState::SVisibleGlyph* hitGlyph
579 = GetHitGlyph (point);
581 if (hitGlyph)
583 ToggleNodeFlag (hitGlyph->node, hitGlyph->state);
584 return __super::OnLButtonDown(nFlags, point);
586 #endif
587 node nodeIndex = GetHitNode (point);
588 if (nodeIndex)
590 if (bControl)
592 if (m_SelectedEntry1 == nodeIndex)
594 if (m_SelectedEntry2)
596 m_SelectedEntry1 = m_SelectedEntry2;
597 m_SelectedEntry2 = nullptr;
599 else
600 m_SelectedEntry1 = nullptr;
602 else if (m_SelectedEntry2 == nodeIndex)
603 m_SelectedEntry2 = nullptr;
604 else if (m_SelectedEntry1)
605 m_SelectedEntry2 = nodeIndex;
606 else
607 m_SelectedEntry1 = nodeIndex;
609 else
611 if (m_SelectedEntry1 == nodeIndex)
612 m_SelectedEntry1 = nullptr;
613 else
614 m_SelectedEntry1 = nodeIndex;
615 m_SelectedEntry2 = nullptr;
617 bHit = true;
618 Invalidate(FALSE);
622 if ((!bHit)&&(!bControl)&&(!bOverview))
624 m_SelectedEntry1 = nullptr;
625 m_SelectedEntry2 = nullptr;
626 m_bIsCanvasMove = true;
627 Invalidate(FALSE);
628 if (m_bShowOverview && m_OverviewRect.PtInRect(point))
629 m_bIsCanvasMove = false;
631 m_ptMoveCanvas = point;
633 UINT uEnable = MF_BYCOMMAND;
634 if (m_SelectedEntry1 && m_SelectedEntry2)
635 uEnable |= MF_ENABLED;
636 else
637 uEnable |= MF_GRAYED;
639 EnableMenuItem(GetParent()->GetMenu()->m_hMenu, ID_VIEW_COMPAREREVISIONS, uEnable);
640 EnableMenuItem(GetParent()->GetMenu()->m_hMenu, ID_VIEW_UNIFIEDDIFF, uEnable);
642 uEnable = MF_BYCOMMAND;
643 if (m_SelectedEntry1 && !m_SelectedEntry2)
644 uEnable |= MF_ENABLED;
645 else
646 uEnable |= MF_GRAYED;
648 EnableMenuItem(GetParent()->GetMenu()->m_hMenu, ID_VIEW_UNIFIEDDIFFOFHEADREVISIONS, uEnable);
649 EnableMenuItem(GetParent()->GetMenu()->m_hMenu, ID_VIEW_COMPAREHEADREVISIONS, uEnable);
651 __super::OnLButtonDown(nFlags, point);
654 void CRevisionGraphWnd::OnCaptureChanged(CWnd *pWnd)
656 __super::OnCaptureChanged(pWnd);
659 void CRevisionGraphWnd::OnLButtonUp(UINT nFlags, CPoint point)
661 if (!m_bIsCanvasMove)
662 return; // we don't have a rubberband, so no zooming necessary
664 m_bIsCanvasMove = false;
665 ReleaseCapture();
666 if (IsUpdateJobRunning())
667 return __super::OnLButtonUp(nFlags, point);
669 // zooming is finished
670 m_ptRubberEnd = CPoint(0,0);
671 CRect rect = GetClientRect();
672 int x = abs(m_ptMoveCanvas.x - point.x);
673 int y = abs(m_ptMoveCanvas.y - point.y);
675 if ((x < 20)&&(y < 20))
677 // too small zoom rectangle
678 // assume zooming by accident
679 Invalidate(FALSE);
680 __super::OnLButtonUp(nFlags, point);
681 return;
684 float xfact = float(rect.Width())/float(x);
685 float yfact = float(rect.Height())/float(y);
686 float fact = max(yfact, xfact);
688 // find out where to scroll to
689 x = min(m_ptMoveCanvas.x, point.x) + GetScrollPos(SB_HORZ);
690 y = min(m_ptMoveCanvas.y, point.y) + GetScrollPos(SB_VERT);
692 float fZoomfactor = m_fZoomFactor*fact;
693 if (fZoomfactor > 10 * MAX_ZOOM)
695 // with such a big zoomfactor, the user
696 // most likely zoomed by accident
697 Invalidate(FALSE);
698 __super::OnLButtonUp(nFlags, point);
699 return;
701 if (fZoomfactor > MAX_ZOOM)
703 fZoomfactor = MAX_ZOOM;
704 fact = fZoomfactor/m_fZoomFactor;
707 auto pDlg = static_cast<CRevisionGraphDlg*>(GetParent());
708 if (pDlg)
710 m_fZoomFactor = fZoomfactor;
711 pDlg->DoZoom (m_fZoomFactor);
712 SetScrollbars(int(float(y)*fact), int(float(x)*fact));
714 __super::OnLButtonUp(nFlags, point);
717 bool CRevisionGraphWnd::CancelMouseZoom()
719 bool bRet = m_bIsCanvasMove;
720 ReleaseCapture();
721 if (m_bIsCanvasMove)
722 Invalidate(FALSE);
723 m_bIsCanvasMove = false;
724 m_ptRubberEnd = CPoint(0,0);
725 return bRet;
728 INT_PTR CRevisionGraphWnd::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
730 if (IsUpdateJobRunning())
731 return -1;
733 node nodeIndex = GetHitNode (point);
734 if (m_tooltipIndex != nodeIndex)
736 // force tooltip to be updated
738 m_tooltipIndex = nodeIndex;
739 return -1;
742 if (!nodeIndex)
743 return -1;
745 // if ((GetHoverGlyphs (point) != 0) || (GetHitGlyph (point) != nullptr))
746 // return -1;
748 pTI->hwnd = this->m_hWnd;
749 CWnd::GetClientRect(&pTI->rect);
750 pTI->uFlags |= TTF_ALWAYSTIP | TTF_IDISHWND;
751 pTI->uId = (UINT_PTR)m_hWnd;
752 pTI->lpszText = LPSTR_TEXTCALLBACK;
754 return 1;
757 BOOL CRevisionGraphWnd::OnToolTipNotify(UINT /*id*/, NMHDR *pNMHDR, LRESULT *pResult)
759 if (pNMHDR->idFrom != (UINT_PTR)m_hWnd)
760 return FALSE;
762 POINT point;
763 DWORD ptW = GetMessagePos();
764 point.x = GET_X_LPARAM(ptW);
765 point.y = GET_Y_LPARAM(ptW);
766 ScreenToClient(&point);
768 CString strTipText = TooltipText (GetHitNode (point));
770 *pResult = 0;
771 if (strTipText.IsEmpty())
772 return TRUE;
774 CSize tooltipSize = UsableTooltipRect();
775 strTipText = DisplayableText (strTipText, tooltipSize);
777 // need to handle both ANSI and UNICODE versions of the message
778 if (pNMHDR->code == TTN_NEEDTEXTA)
780 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
781 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, tooltipSize.cx);
782 pTTTA->lpszText = m_szTip;
783 WideCharToMultiByte(CP_ACP, 0, strTipText, -1, m_szTip, strTipText.GetLength()+1, 0, 0);
785 else
787 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
788 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, tooltipSize.cx);
789 lstrcpyn(m_wszTip, strTipText, strTipText.GetLength()+1);
790 pTTTW->lpszText = m_wszTip;
793 // show the tooltip for 32 seconds. A higher value than 32767 won't work
794 // even though it's nowhere documented!
795 ::SendMessage(pNMHDR->hwndFrom, TTM_SETDELAYTIME, TTDT_AUTOPOP, 32767);
796 return TRUE; // message was handled
799 CSize CRevisionGraphWnd::UsableTooltipRect()
801 // get screen size
803 int screenWidth = GetSystemMetrics(SM_CXSCREEN);
804 int screenHeight = GetSystemMetrics(SM_CYSCREEN);
806 // get current mouse position
808 CPoint cursorPos;
809 if (GetCursorPos (&cursorPos) == FALSE)
811 // we could not determine the mouse position
812 // use screen / 2 minus some safety margin
814 return CSize (screenWidth / 2 - 20, screenHeight / 2 - 20);
817 // tool tip will display in the biggest sector beside the cursor
818 // deduct some safety margin (for the mouse cursor itself
820 CSize biggestSector
821 ( max (screenWidth - cursorPos.x - 40, cursorPos.x - 24)
822 , max (screenHeight - cursorPos.y - 40, cursorPos.y - 24));
824 return biggestSector;
827 CString CRevisionGraphWnd::DisplayableText ( const CString& wholeText
828 , const CSize& tooltipSize)
830 CDC* dc = GetDC();
831 if (!dc)
833 // no access to the device context -> truncate hard at 1000 chars
835 return wholeText.GetLength() >= MAX_TT_LENGTH_DEFAULT
836 ? wholeText.Left(MAX_TT_LENGTH_DEFAULT - 4) + L" ..."
837 : wholeText;
840 // select the tooltip font
842 NONCLIENTMETRICS metrics;
843 metrics.cbSize = sizeof (metrics);
844 SystemParametersInfo (SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0);
846 CFont font;
847 font.CreateFontIndirect(&metrics.lfStatusFont);
848 CFont* pOldFont = dc->SelectObject (&font);
850 // split into lines and fill the tooltip rect
852 CString result;
854 int remainingHeight = tooltipSize.cy;
855 int pos = 0;
856 while (pos < wholeText.GetLength())
858 // extract a whole line
860 int nextPos = wholeText.Find ('\n', pos);
861 if (nextPos < 0)
862 nextPos = wholeText.GetLength();
864 CString line = wholeText.Mid (pos, nextPos-pos+1);
866 // find a way to make it fit
868 CSize size = dc->GetTextExtent (line);
869 while (size.cx > tooltipSize.cx)
871 line.Delete (line.GetLength()-1);
872 int nextPos2 = line.ReverseFind (' ');
873 if (nextPos2 < 0)
874 break;
876 line.Delete (nextPos2+1, line.GetLength() - pos-1);
877 size = dc->GetTextExtent (line);
880 // enough room for the new line?
882 remainingHeight -= size.cy;
883 if (remainingHeight <= size.cy)
885 result += L"...";
886 break;
889 // add the line
891 result += line;
892 pos += line.GetLength();
895 // relase temp. resources
897 dc->SelectObject (pOldFont);
898 ReleaseDC(dc);
900 // ready
902 return result;
905 CString CRevisionGraphWnd::TooltipText(node index)
907 if(index)
909 CString str;
910 CGitHash hash = m_logEntries[index->index()];
911 GitRevLoglist* rev = this->m_LogCache.GetCacheData(hash);
912 str += rev->m_CommitHash.ToString();
913 str += L'\n';
914 str += rev->GetAuthorName() + L' ' + rev->GetAuthorEmail();
915 str += L' ';
916 str += rev->GetAuthorDate().Format(L"%Y-%m-%d %H:%M");
917 str += L"\n\n" + rev->GetSubject();
918 str += L'\n';
919 str += rev->GetBody();
920 return str;
921 }else
922 return CString();
925 void CRevisionGraphWnd::SaveGraphAs(CString sSavePath)
927 CString extension = CPathUtils::GetFileExtFromPath(sSavePath);
928 if (extension.CompareNoCase(L".wmf") == 0)
930 // save the graph as an enhanced metafile
931 CMetaFileDC wmfDC;
932 wmfDC.CreateEnhanced(nullptr, sSavePath, nullptr, L"TortoiseGit\0Revision Graph\0\0");
933 float fZoom = m_fZoomFactor;
934 m_fZoomFactor = DEFAULT_ZOOM;
935 DoZoom(m_fZoomFactor);
936 CRect rect;
937 rect = GetViewRect();
938 GraphicsDevice dev;
939 dev.pDC = &wmfDC;
940 DrawGraph(dev, rect, 0, 0, true);
941 HENHMETAFILE hemf = wmfDC.CloseEnhanced();
942 DeleteEnhMetaFile(hemf);
943 m_fZoomFactor = fZoom;
944 DoZoom(m_fZoomFactor);
946 else if (extension.CompareNoCase(L".svg") == 0)
948 // save the graph as a scalable vector graphic
949 SVG svg;
950 float fZoom = m_fZoomFactor;
951 m_fZoomFactor = DEFAULT_ZOOM;
952 DoZoom(m_fZoomFactor);
953 CRect rect;
954 rect = GetViewRect();
955 svg.SetViewSize(rect.Width(), rect.Height());
956 GraphicsDevice dev;
957 dev.pSVG = &svg;
958 DrawGraph(dev, rect, 0, 0, true);
959 svg.Save(sSavePath);
960 m_fZoomFactor = fZoom;
961 DoZoom(m_fZoomFactor);
963 else if (extension.CompareNoCase(L".gv") == 0)
965 Graphviz graphviz;
966 float fZoom = m_fZoomFactor;
967 m_fZoomFactor = DEFAULT_ZOOM;
968 DoZoom(m_fZoomFactor);
969 CRect rect;
970 rect = GetViewRect();
971 GraphicsDevice dev;
972 dev.pGraphviz = &graphviz;
973 DrawGraph(dev, rect, 0, 0, true);
974 graphviz.Save(sSavePath);
975 m_fZoomFactor = fZoom;
976 DoZoom(m_fZoomFactor);
978 else
980 // save the graph as a pixel picture instead of a vector picture
981 // create dc to paint on
984 CString sErrormessage;
985 CWindowDC ddc(this);
986 CDC dc;
987 if (!dc.CreateCompatibleDC(&ddc))
989 CFormatMessageWrapper errorDetails;
990 if( errorDetails )
991 MessageBox(errorDetails, L"Error", MB_OK | MB_ICONINFORMATION);
993 return;
995 CRect rect;
996 rect = GetGraphRect();
997 rect.bottom = (LONG)(float(rect.Height()) * m_fZoomFactor);
998 rect.right = (LONG)(float(rect.Width()) * m_fZoomFactor);
999 BITMAPINFO bmi = { 0 };
1000 HBITMAP hbm;
1001 LPBYTE pBits;
1002 // Fill out the fields you care about.
1003 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1004 bmi.bmiHeader.biWidth = rect.Width();
1005 bmi.bmiHeader.biHeight = rect.Height();
1006 bmi.bmiHeader.biPlanes = 1;
1007 bmi.bmiHeader.biBitCount = 24;
1008 bmi.bmiHeader.biCompression = BI_RGB;
1010 // Create the surface.
1011 hbm = CreateDIBSection(ddc.m_hDC, &bmi, DIB_RGB_COLORS,(void**)&pBits, nullptr, 0);
1012 if (!hbm)
1014 CMessageBox::Show(m_hWnd, IDS_REVGRAPH_ERR_NOMEMORY, IDS_APPNAME, MB_ICONERROR);
1015 return;
1017 HBITMAP oldbm = (HBITMAP)dc.SelectObject(hbm);
1018 // paint the whole graph
1019 GraphicsDevice dev;
1020 dev.pDC = &dc;
1021 DrawGraph(dev, rect, 0, 0, true);
1022 // now use GDI+ to save the picture
1023 CLSID encoderClsid;
1025 Bitmap bitmap(hbm, nullptr);
1026 if (bitmap.GetLastStatus()==Ok)
1028 // Get the CLSID of the encoder.
1029 int ret = 0;
1030 if (CPathUtils::GetFileExtFromPath(sSavePath).CompareNoCase(L".png") == 0)
1031 ret = GetEncoderClsid(L"image/png", &encoderClsid);
1032 else if (CPathUtils::GetFileExtFromPath(sSavePath).CompareNoCase(L".jpg") == 0)
1033 ret = GetEncoderClsid(L"image/jpeg", &encoderClsid);
1034 else if (CPathUtils::GetFileExtFromPath(sSavePath).CompareNoCase(L".jpeg") == 0)
1035 ret = GetEncoderClsid(L"image/jpeg", &encoderClsid);
1036 else if (CPathUtils::GetFileExtFromPath(sSavePath).CompareNoCase(L".bmp") == 0)
1037 ret = GetEncoderClsid(L"image/bmp", &encoderClsid);
1038 else if (CPathUtils::GetFileExtFromPath(sSavePath).CompareNoCase(L".gif") == 0)
1039 ret = GetEncoderClsid(L"image/gif", &encoderClsid);
1040 else
1042 sSavePath += L".jpg";
1043 ret = GetEncoderClsid(L"image/jpeg", &encoderClsid);
1045 if (ret >= 0)
1047 CStringW tfile = CStringW(sSavePath);
1048 bitmap.Save(tfile, &encoderClsid, nullptr);
1050 else
1051 sErrormessage.Format(IDS_REVGRAPH_ERR_NOENCODER, (LPCTSTR)CPathUtils::GetFileExtFromPath(sSavePath));
1053 else
1054 sErrormessage.LoadString(IDS_REVGRAPH_ERR_NOBITMAP);
1056 dc.SelectObject(oldbm);
1057 DeleteObject(hbm);
1058 dc.DeleteDC();
1059 if (!sErrormessage.IsEmpty())
1060 ::MessageBox(m_hWnd, sErrormessage, L"TortoiseGit", MB_ICONERROR);
1062 catch (CException * pE)
1064 TCHAR szErrorMsg[2048] = { 0 };
1065 pE->GetErrorMessage(szErrorMsg, 2048);
1066 pE->Delete();
1067 ::MessageBox(m_hWnd, szErrorMsg, L"TortoiseGit", MB_ICONERROR);
1072 BOOL CRevisionGraphWnd::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
1074 if (IsUpdateJobRunning())
1075 return __super::OnMouseWheel(nFlags, zDelta, pt);
1077 if (GetKeyState(VK_CONTROL)&0x8000)
1079 float newZoom = m_fZoomFactor * (zDelta < 0 ? ZOOM_STEP : 1.0f/ZOOM_STEP);
1080 DoZoom (max (MIN_ZOOM, min (MAX_ZOOM, newZoom)));
1082 else
1084 int orientation = (GetKeyState(VK_SHIFT) & 0x8000) ? SB_HORZ : SB_VERT;
1085 int pos = GetScrollPos(orientation);
1086 pos -= (zDelta);
1087 SetScrollPos(orientation, pos);
1088 Invalidate(FALSE);
1090 return __super::OnMouseWheel(nFlags, zDelta, pt);
1093 void CRevisionGraphWnd::OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt)
1095 if (IsUpdateJobRunning())
1096 return __super::OnMouseHWheel(nFlags, zDelta, pt);
1098 int orientation = (GetKeyState(VK_SHIFT) & 0x8000) ? SB_VERT : SB_HORZ;
1099 int pos = GetScrollPos(orientation);
1100 pos -= (zDelta);
1101 SetScrollPos(orientation, pos);
1102 Invalidate(FALSE);
1104 return __super::OnMouseHWheel(nFlags, zDelta, pt);
1107 bool CRevisionGraphWnd::UpdateSelectedEntry (node clickedentry)
1109 if (!m_SelectedEntry1 && !clickedentry)
1110 return false;
1112 if (!m_SelectedEntry1)
1114 m_SelectedEntry1 = clickedentry;
1115 Invalidate(FALSE);
1117 if (!m_SelectedEntry2 && clickedentry != m_SelectedEntry1)
1119 m_SelectedEntry1 = clickedentry;
1120 Invalidate(FALSE);
1122 if (m_SelectedEntry1 && m_SelectedEntry2)
1124 if ((m_SelectedEntry2 != clickedentry)&&(m_SelectedEntry1 != clickedentry))
1125 return false;
1127 if (!m_SelectedEntry1)
1128 return false;
1130 return true;
1133 void CRevisionGraphWnd::AppendMenu
1134 ( CMenu& popup
1135 , UINT title
1136 , UINT command
1137 , UINT flags)
1139 // separate different groups / section within the context menu
1141 if (popup.GetMenuItemCount() > 0)
1143 UINT lastCommand = popup.GetMenuItemID (popup.GetMenuItemCount()-1);
1144 if ((lastCommand & GROUP_MASK) != (command & GROUP_MASK))
1145 popup.AppendMenu(MF_SEPARATOR, NULL);
1148 // actually add the new item
1150 CString titleString;
1151 titleString.LoadString (title);
1152 popup.AppendMenu (MF_STRING | flags, command, titleString);
1155 void CRevisionGraphWnd::AppendMenu(CMenu &popup, CString title, UINT command, CString *extra, CMenu *submenu)
1157 // separate different groups / section within the context menu
1158 if (popup.GetMenuItemCount() > 0)
1160 UINT lastCommand = popup.GetMenuItemID(popup.GetMenuItemCount() - 1);
1161 if ((lastCommand & GROUP_MASK) != (command & GROUP_MASK))
1162 popup.AppendMenu(MF_SEPARATOR, NULL);
1165 // actually add the new item
1166 MENUITEMINFO mii = { 0 };
1167 mii.cbSize = sizeof(MENUITEMINFO);
1168 mii.fMask = MIIM_STRING | MIIM_ID | (extra ? MIIM_DATA : 0) | (submenu ? MIIM_SUBMENU : 0);
1169 mii.wID = command;
1170 mii.hSubMenu = submenu ? submenu->m_hMenu : nullptr;
1171 mii.dwItemData = (ULONG_PTR)extra;
1172 mii.dwTypeData = title.GetBuffer();
1173 InsertMenuItem(popup, popup.GetMenuItemCount(), TRUE, &mii);
1174 title.ReleaseBuffer();
1177 void CRevisionGraphWnd::AddGraphOps (CMenu& /*popup*/, const CVisibleGraphNode * /*node*/)
1179 #if 0
1180 CSyncPointer<CGraphNodeStates> nodeStates (m_state.GetNodeStates());
1182 if (!node)
1184 DWORD state = nodeStates->GetCombinedFlags();
1185 if (state != 0)
1187 if (state & CGraphNodeStates::COLLAPSED_ALL)
1188 AppendMenu (popup, IDS_REVGRAPH_POPUP_EXPAND_ALL, ID_EXPAND_ALL);
1190 if (state & CGraphNodeStates::SPLIT_ALL)
1191 AppendMenu (popup, IDS_REVGRAPH_POPUP_JOIN_ALL, ID_JOIN_ALL);
1194 else
1196 DWORD state = nodeStates->GetFlags (node);
1198 if (node->GetSource() || (state & CGraphNodeStates::COLLAPSED_ABOVE))
1199 AppendMenu ( popup
1200 , (state & CGraphNodeStates::COLLAPSED_ABOVE)
1201 ? IDS_REVGRAPH_POPUP_EXPAND_ABOVE
1202 : IDS_REVGRAPH_POPUP_COLLAPSE_ABOVE
1203 , ID_GRAPH_EXPANDCOLLAPSE_ABOVE);
1205 if (node->GetFirstCopyTarget() || (state & CGraphNodeStates::COLLAPSED_RIGHT))
1206 AppendMenu ( popup
1207 , (state & CGraphNodeStates::COLLAPSED_RIGHT)
1208 ? IDS_REVGRAPH_POPUP_EXPAND_RIGHT
1209 : IDS_REVGRAPH_POPUP_COLLAPSE_RIGHT
1210 , ID_GRAPH_EXPANDCOLLAPSE_RIGHT);
1212 if (node->GetNext() || (state & CGraphNodeStates::COLLAPSED_BELOW))
1213 AppendMenu ( popup
1214 , (state & CGraphNodeStates::COLLAPSED_BELOW)
1215 ? IDS_REVGRAPH_POPUP_EXPAND_BELOW
1216 : IDS_REVGRAPH_POPUP_COLLAPSE_BELOW
1217 , ID_GRAPH_EXPANDCOLLAPSE_BELOW);
1219 if (node->GetSource() || (state & CGraphNodeStates::SPLIT_ABOVE))
1220 AppendMenu ( popup
1221 , (state & CGraphNodeStates::SPLIT_ABOVE)
1222 ? IDS_REVGRAPH_POPUP_JOIN_ABOVE
1223 : IDS_REVGRAPH_POPUP_SPLIT_ABOVE
1224 , ID_GRAPH_SPLITJOIN_ABOVE);
1226 if (node->GetFirstCopyTarget() || (state & CGraphNodeStates::SPLIT_RIGHT))
1227 AppendMenu ( popup
1228 , (state & CGraphNodeStates::SPLIT_RIGHT)
1229 ? IDS_REVGRAPH_POPUP_JOIN_RIGHT
1230 : IDS_REVGRAPH_POPUP_SPLIT_RIGHT
1231 , ID_GRAPH_SPLITJOIN_RIGHT);
1233 if (node->GetNext() || (state & CGraphNodeStates::SPLIT_BELOW))
1234 AppendMenu ( popup
1235 , (state & CGraphNodeStates::SPLIT_BELOW)
1236 ? IDS_REVGRAPH_POPUP_JOIN_BELOW
1237 : IDS_REVGRAPH_POPUP_SPLIT_BELOW
1238 , ID_GRAPH_SPLITJOIN_BELOW);
1240 #endif
1243 CString CRevisionGraphWnd::GetSelectedURL() const
1245 #if 0
1246 if (!m_SelectedEntry1)
1247 return CString();
1249 CString URL = m_state.GetRepositoryRoot()
1250 + CUnicodeUtils::GetUnicode (m_SelectedEntry1->GetPath().GetPath().c_str());
1251 URL = CUnicodeUtils::GetUnicode(CPathUtils::PathEscape(CUnicodeUtils::GetUTF8(URL)));
1253 return URL;
1254 #endif
1255 return CString();
1258 CString CRevisionGraphWnd::GetWCURL() const
1260 #if 0
1261 CTGitPath path (m_sPath);
1262 if (path.IsUrl())
1263 return CString();
1265 SVNInfo info;
1266 const SVNInfoData * status
1267 = info.GetFirstFileInfo (path, SVNRev(), SVNRev());
1269 return !status ? CString() : status->url;
1270 #endif
1271 return CString();
1274 void CRevisionGraphWnd::DoShowLog()
1276 if (!m_SelectedEntry1)
1277 return;
1279 CString sCmd;
1281 if(m_SelectedEntry2)
1282 sCmd.Format(L"/command:log %s /startrev:%s /endrev:%s",
1283 this->m_sPath.IsEmpty() ? L"" : (LPCTSTR)(L"/path:\"" + this->m_sPath + L'"'),
1284 (LPCTSTR)this->m_logEntries[m_SelectedEntry1->index()].ToString(),
1285 (LPCTSTR)this->m_logEntries[m_SelectedEntry2->index()].ToString());
1286 else
1287 sCmd.Format(L"/command:log %s /endrev:%s",
1288 (LPCTSTR)this->m_sPath.IsEmpty() ? L"" : (L"/path:\"" + this->m_sPath + L'"'),
1289 (LPCTSTR)this->m_logEntries[m_SelectedEntry1->index()].ToString());
1291 CAppUtils::RunTortoiseGitProc(sCmd);
1294 void CRevisionGraphWnd::DoCheckForModification()
1296 CChangedDlg dlg;
1297 dlg.m_pathList = CTGitPathList (CTGitPath (m_sPath));
1298 dlg.DoModal();
1301 void CRevisionGraphWnd::DoMergeTo()
1303 #if 0
1304 CString URL = GetSelectedURL();
1305 CString path = m_sPath;
1306 CBrowseFolder folderBrowser;
1307 folderBrowser.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_MERGETO)));
1308 if (folderBrowser.Show(GetSafeHwnd(), path, path) == CBrowseFolder::OK)
1310 CSVNProgressDlg dlg;
1311 dlg.SetCommand(CSVNProgressDlg::SVNProgress_Merge);
1312 dlg.SetPathList(CTGitPathList(CTGitPath(path)));
1313 dlg.SetUrl(URL);
1314 dlg.SetSecondUrl(URL);
1315 SVNRevRangeArray revarray;
1316 revarray.AddRevRange (m_SelectedEntry1->GetRevision()-1, svn_revnum_t(m_SelectedEntry1->GetRevision()));
1317 dlg.SetRevisionRanges(revarray);
1318 dlg.DoModal();
1320 #endif
1323 void CRevisionGraphWnd::DoUpdate()
1325 #if 0
1326 CSVNProgressDlg progDlg;
1327 progDlg.SetCommand (CSVNProgressDlg::SVNProgress_Update);
1328 progDlg.SetOptions (0); // don't ignore externals
1329 progDlg.SetPathList (CTGitPathList (CTGitPath (m_sPath)));
1330 progDlg.SetRevision (m_SelectedEntry1->GetRevision());
1331 progDlg.SetDepth();
1332 progDlg.DoModal();
1334 if (m_state.GetFetchedWCState())
1335 m_parent->UpdateFullHistory();
1336 #endif
1339 void CRevisionGraphWnd::DoSwitch(CString rev)
1341 CAppUtils::PerformSwitch(rev);
1344 void CRevisionGraphWnd::DoSwitchToHead()
1346 #if 0
1347 CSVNProgressDlg progDlg;
1348 progDlg.SetCommand (CSVNProgressDlg::SVNProgress_Switch);
1349 progDlg.SetPathList (CTGitPathList (CTGitPath (m_sPath)));
1350 progDlg.SetUrl (GetSelectedURL());
1351 progDlg.SetRevision (SVNRev::REV_HEAD);
1352 progDlg.SetPegRevision (m_SelectedEntry1->GetRevision());
1353 progDlg.DoModal();
1355 if (m_state.GetFetchedWCState())
1356 m_parent->UpdateFullHistory();
1357 #endif
1360 void CRevisionGraphWnd::DoBrowseRepo()
1362 if (!m_SelectedEntry1)
1363 return;
1365 CString sCmd;
1366 sCmd.Format(L"/command:repobrowser %s /rev:%s",
1367 this->m_sPath.IsEmpty() ? L"" : (LPCTSTR)(L"/path:\"" + this->m_sPath + L'"'),
1368 (LPCTSTR)GetFriendRefName(m_SelectedEntry1));
1370 CAppUtils::RunTortoiseGitProc(sCmd);
1373 void CRevisionGraphWnd::ResetNodeFlags (DWORD /*flags*/)
1375 // m_state.GetNodeStates()->ResetFlags (flags);
1376 // m_parent->StartWorkerThread();
1379 void CRevisionGraphWnd::ToggleNodeFlag (const CVisibleGraphNode * /*node*/, DWORD /*flag*/)
1381 #if 0
1382 CSyncPointer<CGraphNodeStates> nodeStates (m_state.GetNodeStates());
1384 if (nodeStates->GetFlags (node) & flag)
1385 nodeStates->ResetFlags (node, flag);
1386 else
1387 nodeStates->SetFlags (node, flag);
1389 m_parent->StartWorkerThread();
1390 #endif
1393 void CRevisionGraphWnd::DoCopyRefs()
1395 if (!m_SelectedEntry1)
1396 return;
1398 STRING_VECTOR list = GetFriendRefNames(m_SelectedEntry1);
1399 CString text;
1400 if (list.empty())
1401 text = m_logEntries[m_SelectedEntry1->index()].ToString();
1402 for (size_t i = 0; i < list.size(); ++i)
1404 if (i > 0)
1405 text.Append(L"\r\n");
1406 text.Append(list[i]);
1408 CStringUtils::WriteAsciiStringToClipboard(text, m_hWnd);
1411 void CRevisionGraphWnd::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
1413 if (IsUpdateJobRunning())
1414 return;
1416 CPoint clientpoint = point;
1417 this->ScreenToClient(&clientpoint);
1419 node nodeIndex = GetHitNode (clientpoint);
1421 if ( !UpdateSelectedEntry (nodeIndex))
1422 return;
1424 CMenu popup;
1425 if (!popup.CreatePopupMenu())
1426 return;
1428 bool bothPresent = (m_SelectedEntry2 && m_SelectedEntry1);
1430 AppendMenu (popup, IDS_REPOBROWSE_SHOWLOG, ID_SHOWLOG);
1432 STRING_VECTOR branchNames;
1433 if (m_SelectedEntry1 && (m_SelectedEntry2 == nullptr))
1435 AppendMenu(popup, IDS_LOG_BROWSEREPO, ID_BROWSEREPO);
1437 CString currentBranch = g_Git.GetCurrentBranch();
1438 CGit::REF_TYPE refType = CGit::LOCAL_BRANCH;
1439 STRING_VECTOR allBranchNames = GetFriendRefNames(m_SelectedEntry1, &refType, 1);
1440 for (size_t i = 0; i < allBranchNames.size(); ++i)
1441 if (allBranchNames[i] != currentBranch)
1442 branchNames.push_back(allBranchNames[i]);
1443 if (branchNames.size() == 1)
1445 CString text;
1446 text.Format(L"%s \"%s\"", (LPCTSTR)CString(MAKEINTRESOURCE(IDS_SWITCH_BRANCH)), (LPCTSTR)branchNames[0]);
1447 AppendMenu(popup, text, ID_SWITCH, &branchNames[0]);
1449 else if (branchNames.size() > 1)
1451 CMenu switchMenu;
1452 switchMenu.CreatePopupMenu();
1453 for (size_t i = 0; i < branchNames.size(); ++i)
1454 AppendMenu(switchMenu, branchNames[i], ID_SWITCH + ((int)(i + 1) << 16), &branchNames[i]);
1455 AppendMenu(popup, CString(MAKEINTRESOURCE(IDS_SWITCH_BRANCH)), ID_SWITCH, nullptr, &switchMenu);
1458 AppendMenu(popup, IDS_COPY_REF_NAMES, ID_COPYREFS);
1460 AppendMenu(popup, IDS_REVGRAPH_POPUP_COMPAREHEADS, ID_COMPAREHEADS);
1461 AppendMenu(popup, IDS_REVGRAPH_POPUP_UNIDIFFHEADS, ID_UNIDIFFHEADS);
1463 AppendMenu(popup, IDS_LOG_POPUP_COMPARE, ID_COMPAREWT);
1466 if (bothPresent)
1468 AppendMenu (popup, IDS_REVGRAPH_POPUP_COMPAREREVS, ID_COMPAREREVS);
1469 AppendMenu (popup, IDS_REVGRAPH_POPUP_UNIDIFFREVS, ID_UNIDIFFREVS);
1472 // AddGraphOps (popup, clickedentry);
1474 // if the context menu is invoked through the keyboard, we have to use
1475 // a calculated position on where to anchor the menu on
1476 if ((point.x == -1) && (point.y == -1))
1478 CRect rect = GetWindowRect();
1479 point = rect.CenterPoint();
1482 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON, point.x, point.y, this);
1483 switch (cmd & 0xFFFF)
1485 case ID_COMPAREREVS:
1486 if (m_SelectedEntry1)
1487 CompareRevs(false);
1488 break;
1489 case ID_UNIDIFFREVS:
1490 if (m_SelectedEntry1)
1491 UnifiedDiffRevs(false);
1492 break;
1493 case ID_UNIDIFFHEADS:
1494 if (m_SelectedEntry1)
1495 UnifiedDiffRevs(true);
1496 break;
1497 case ID_SHOWLOG:
1498 DoShowLog();
1499 break;
1500 case ID_SWITCH:
1502 MENUITEMINFO mii = { 0 };
1503 mii.cbSize = sizeof(mii);
1504 mii.fMask |= MIIM_DATA;
1505 GetMenuItemInfo(popup, cmd, FALSE, &mii);
1506 CString *rev = (CString *)mii.dwItemData;
1507 if (rev)
1509 DoSwitch(*rev);
1510 m_parent->UpdateFullHistory();
1512 break;
1514 case ID_COPYREFS:
1515 DoCopyRefs();
1516 break;
1517 case ID_BROWSEREPO:
1518 DoBrowseRepo();
1519 break;
1520 case ID_COMPAREHEADS:
1521 if (m_SelectedEntry1)
1522 CompareRevs(L"HEAD");
1523 break;
1524 case ID_COMPAREWT:
1525 if (m_SelectedEntry1)
1526 CompareRevs(CGitHash().ToString());
1527 break;
1529 #if 0
1530 case ID_COMPAREREVS:
1531 if (m_SelectedEntry1)
1532 CompareRevs(false);
1533 break;
1534 case ID_UNIDIFFREVS:
1535 if (m_SelectedEntry1)
1536 UnifiedDiffRevs(false);
1537 break;
1538 case ID_UNIDIFFHEADS:
1539 if (m_SelectedEntry1)
1540 UnifiedDiffRevs(true);
1541 break;
1542 case ID_SHOWLOG:
1543 DoShowLog();
1544 break;
1545 case ID_CFM:
1546 DoCheckForModification();
1547 break;
1548 case ID_MERGETO:
1549 DoMergeTo();
1550 break;
1551 case ID_UPDATE:
1552 DoUpdate();
1553 break;
1554 case ID_SWITCHTOHEAD:
1555 DoSwitchToHead();
1556 break;
1557 case ID_EXPAND_ALL:
1558 ResetNodeFlags (CGraphNodeStates::COLLAPSED_ALL);
1559 break;
1560 case ID_JOIN_ALL:
1561 ResetNodeFlags (CGraphNodeStates::SPLIT_ALL);
1562 break;
1563 case ID_GRAPH_EXPANDCOLLAPSE_ABOVE:
1564 ToggleNodeFlag (clickedentry, CGraphNodeStates::COLLAPSED_ABOVE);
1565 break;
1566 case ID_GRAPH_EXPANDCOLLAPSE_RIGHT:
1567 ToggleNodeFlag (clickedentry, CGraphNodeStates::COLLAPSED_RIGHT);
1568 break;
1569 case ID_GRAPH_EXPANDCOLLAPSE_BELOW:
1570 ToggleNodeFlag (clickedentry, CGraphNodeStates::COLLAPSED_BELOW);
1571 break;
1572 case ID_GRAPH_SPLITJOIN_ABOVE:
1573 ToggleNodeFlag (clickedentry, CGraphNodeStates::SPLIT_ABOVE);
1574 break;
1575 case ID_GRAPH_SPLITJOIN_RIGHT:
1576 ToggleNodeFlag (clickedentry, CGraphNodeStates::SPLIT_RIGHT);
1577 break;
1578 case ID_GRAPH_SPLITJOIN_BELOW:
1579 ToggleNodeFlag (clickedentry, CGraphNodeStates::SPLIT_BELOW);
1580 break;
1581 #endif
1585 void CRevisionGraphWnd::OnMouseMove(UINT nFlags, CPoint point)
1587 if (IsUpdateJobRunning())
1588 return __super::OnMouseMove(nFlags, point);
1589 if (!m_bIsCanvasMove)
1591 if (m_bShowOverview && (m_OverviewRect.PtInRect(point))&&(nFlags & MK_LBUTTON))
1593 // scrolling
1594 int x = (int)((point.x-m_OverviewRect.left - (m_OverviewPosRect.Width()/2)) / m_previewZoom * m_fZoomFactor);
1595 int y = (int)((point.y - m_OverviewRect.top - (m_OverviewPosRect.Height()/2)) / m_previewZoom * m_fZoomFactor);
1596 x = max(0, x);
1597 y = max(0, y);
1598 SetScrollbars(y, x);
1599 Invalidate(FALSE);
1600 return __super::OnMouseMove(nFlags, point);
1602 else
1604 // update screen if we hover over a different
1605 // node than during the last redraw
1607 CPoint clientPoint = point;
1608 GetCursorPos (&clientPoint);
1609 ScreenToClient (&clientPoint);
1611 #if 0
1612 const CRevisionGraphState::SVisibleGlyph* hitGlyph
1613 = GetHitGlyph (clientPoint);
1614 const CFullGraphNode* glyphNode
1615 = hitGlyph ? hitGlyph->node->GetBase() : nullptr;
1617 const CFullGraphNode* hoverNode = nullptr;
1618 if (m_hoverIndex != NO_INDEX)
1620 CSyncPointer<const ILayoutNodeList> nodeList (m_state.GetNodes());
1621 if (m_hoverIndex < nodeList->GetCount())
1622 hoverNode = nodeList->GetNode (m_hoverIndex).node->GetBase();
1625 //bool onHoverNodeGlyph = hoverNode && (glyphNode == hoverNode);
1626 if ( !m_hoverIndex
1627 && ( (m_hoverIndex != GetHitNode (clientPoint))))
1629 m_showHoverGlyphs = false;
1631 KillTimer (GLYPH_HOVER_EVENT);
1632 SetTimer(GLYPH_HOVER_EVENT, GLYPH_HOVER_DELAY, nullptr);
1634 Invalidate(FALSE);
1636 #endif
1637 return __super::OnMouseMove(nFlags, point);
1640 SetCapture();
1642 int pos_h = GetScrollPos(SB_HORZ);
1643 pos_h -= point.x - m_ptMoveCanvas.x;
1644 SetScrollPos(SB_HORZ, pos_h);
1646 int pos_v = GetScrollPos(SB_VERT);
1647 pos_v -= point.y - m_ptMoveCanvas.y;
1648 SetScrollPos(SB_VERT, pos_v);
1650 m_ptMoveCanvas = point;
1652 this->Invalidate();
1654 __super::OnMouseMove(nFlags, point);
1657 BOOL CRevisionGraphWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1659 CRect viewRect = GetViewRect();
1661 LPTSTR cursorID = IDC_ARROW;
1662 HINSTANCE resourceHandle = nullptr;
1664 if ((nHitTest == HTCLIENT)&&(pWnd == this)&&(viewRect.Width())&&(viewRect.Height())&&(message))
1666 POINT pt;
1667 if (GetCursorPos(&pt))
1669 ScreenToClient(&pt);
1670 if (m_OverviewPosRect.PtInRect(pt))
1672 resourceHandle = AfxGetResourceHandle();
1673 cursorID = (GetKeyState(VK_LBUTTON) & 0x8000)
1674 ? MAKEINTRESOURCE(IDC_PANCURDOWN)
1675 : MAKEINTRESOURCE(IDC_PANCUR);
1677 if (m_bIsCanvasMove)
1678 cursorID = IDC_HAND;
1682 HCURSOR hCur = LoadCursor(resourceHandle, cursorID);
1683 if (GetCursor() != hCur)
1684 SetCursor (hCur);
1686 return TRUE;
1689 void CRevisionGraphWnd::OnTimer (UINT_PTR nIDEvent)
1691 if (nIDEvent == GLYPH_HOVER_EVENT)
1693 KillTimer (GLYPH_HOVER_EVENT);
1695 m_showHoverGlyphs = true;
1696 Invalidate (FALSE);
1698 else
1699 __super::OnTimer (nIDEvent);
1702 LRESULT CRevisionGraphWnd::OnWorkerThreadDone(WPARAM, LPARAM)
1704 // handle potential race condition between PostMessage and leaving job:
1705 // the background job may not have exited, yet
1707 if (updateJob.get())
1708 updateJob->GetResult();
1710 InitView();
1711 BuildPreview();
1713 if (m_HeadNode)
1715 SCROLLINFO sinfo = { 0 };
1716 sinfo.cbSize = sizeof(SCROLLINFO);
1717 if (GetScrollInfo(SB_HORZ, &sinfo))
1719 sinfo.nPos = (int)min(max(sinfo.nMin, m_GraphAttr.x(m_HeadNode) - m_GraphAttr.width(m_HeadNode) / 2), sinfo.nMax);
1720 SetScrollInfo(SB_HORZ, &sinfo);
1722 if (GetScrollInfo(SB_VERT, &sinfo))
1724 sinfo.nPos = (int)min(max(sinfo.nMin, m_GraphAttr.y(m_HeadNode) - m_GraphAttr.height(m_HeadNode) / 2), sinfo.nMax);
1725 SetScrollInfo(SB_VERT, &sinfo);
1729 Invalidate(FALSE);
1731 if (m_parent && !m_parent->GetOutputFile().IsEmpty())
1733 // save the graph to the output file and exit
1734 SaveGraphAs(m_parent->GetOutputFile());
1735 PostQuitMessage(0);
1737 return 0;
1740 void CRevisionGraphWnd::SetDlgTitle (bool /*offline*/)
1742 #if 0
1743 if (m_sTitle.IsEmpty())
1744 GetParent()->GetWindowText(m_sTitle);
1746 CString newTitle;
1747 if (offline)
1748 newTitle.Format (IDS_REVGRAPH_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle);
1749 else
1750 newTitle = m_sTitle;
1752 CAppUtils::SetWindowTitle(GetParent()->GetSafeHwnd(), m_sPath, newTitle);
1753 #endif