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.
21 #include "TortoiseProc.h"
22 #include "Revisiongraphwnd.h"
23 #include "MessageBox.h"
26 #include "PathUtils.h"
27 #include "StringUtils.h"
29 #include "UnicodeUtils.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"
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>
52 static char THIS_FILE
[] = __FILE__
;
55 using namespace Gdiplus
;
58 enum RevisionGraphContextMenuCommands
60 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
65 ID_COMPAREREVS
= 0x100,
75 ID_EXPAND_ALL
= 0x500,
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()
87 , m_SelectedEntry1(nullptr)
88 , m_SelectedEntry2(nullptr)
92 , m_bTweakTrunkColors(true)
93 , m_bTweakTagsColors(true)
94 , m_fZoomFactor(DEFAULT_ZOOM
)
97 , m_bShowOverview(false)
99 , m_hoverIndex(nullptr)
101 , m_tooltipIndex(nullptr)
102 , m_showHoverGlyphs (false)
103 , m_bIsCanvasMove(false)
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);
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
;
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;
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
);
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
);
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
);
193 PlanarizationLayout pl
;
195 FastPlanarSubgraph
*ps
= ::new FastPlanarSubgraph
;
197 VariableEmbeddingInserter
*ves
= ::new VariableEmbeddingInserter
;
198 ves
->removeReinsert(EdgeInsertionModule::rrAll
);
202 EmbedderMinDepthMaxFaceLayers
*emb
= ::new EmbedderMinDepthMaxFaceLayers
;
205 OrthoLayout
*ol
=::new OrthoLayout
;
206 ol
->separation(20.0);
209 ol
->preferedDir(OrthoDir::odEast
);
210 pl
.setPlanarLayouter(ol
);
212 pl
.call(m_GraphAttr
);
215 forall_nodes(v
,m_Graph
) {
216 TRACE(L
"node x %f y %f %f %f\n",/* m_GraphAttr.idNode(v), */
219 m_GraphAttr
.width(v
),
220 m_GraphAttr
.height(v
)
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");
240 CRevisionGraphWnd::~CRevisionGraphWnd()
242 for (int i
= 0; i
< MAXFONTS
; ++i
)
246 m_apFonts
[i
]->DeleteObject();
249 m_apFonts
[i
] = nullptr;
255 void CRevisionGraphWnd::DoDataExchange(CDataExchange
* pDX
)
257 CWnd::DoDataExchange(pDX
);
261 BEGIN_MESSAGE_MAP(CRevisionGraphWnd
, CWnd
)
268 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, OnToolTipNotify
)
269 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, OnToolTipNotify
)
277 ON_MESSAGE(WM_WORKERTHREADDONE
,OnWorkerThreadDone
)
278 ON_WM_CAPTURECHANGED()
281 void CRevisionGraphWnd::Init(CWnd
* pParent
, LPRECT rect
)
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");
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
342 CSyncPointer
<const ILayoutNodeList
> nodeList (m_state
.GetNodes());
344 return index_t(NO_INDEX
);
346 // search the nodes for one at that grid position
348 return nodeList
->GetAt (GetLogCoordinates (point
), border
);
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
))
364 DWORD
CRevisionGraphWnd::GetHoverGlyphs (CPoint
/*point*/) const
366 // if there is no layout, there will be no nodes,
370 CSyncPointer
<const ILayoutNodeList
> nodeList (m_state
.GetNodes());
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())
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
);
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);
402 = m_state
.GetOptions()->GetOption
<CUpsideDownLayout
>()->IsActive();
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
416 if (topGlyphArea
.PtInRect (logCoordinates
))
417 result
= base
->GetSource()
418 ? CGraphNodeStates::COLLAPSED_ABOVE
| CGraphNodeStates::SPLIT_ABOVE
421 if (bottomGlyphArea
.PtInRect (logCoordinates
))
422 result
= base
->GetNext()
423 ? CGraphNodeStates::COLLAPSED_BELOW
| CGraphNodeStates::SPLIT_BELOW
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
))
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
))
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.
468 case SB_LEFT
: // Scroll to far left.
469 sinfo
.nPos
= sinfo
.nMin
;
471 case SB_RIGHT
: // Scroll to far right.
472 sinfo
.nPos
= sinfo
.nMax
;
474 case SB_ENDSCROLL
: // End scroll.
476 case SB_LINELEFT
: // Scroll left.
477 if (sinfo
.nPos
> sinfo
.nMin
)
480 case SB_LINERIGHT
: // Scroll right.
481 if (sinfo
.nPos
< sinfo
.nMax
)
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
);
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
);
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.
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.
503 SetScrollInfo(SB_HORZ
, &sinfo
);
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.
517 case SB_LEFT
: // Scroll to far left.
518 sinfo
.nPos
= sinfo
.nMin
;
520 case SB_RIGHT
: // Scroll to far right.
521 sinfo
.nPos
= sinfo
.nMax
;
523 case SB_ENDSCROLL
: // End scroll.
525 case SB_LINELEFT
: // Scroll left.
526 if (sinfo
.nPos
> sinfo
.nMin
)
529 case SB_LINERIGHT
: // Scroll right.
530 if (sinfo
.nPos
< sinfo
.nMax
)
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
);
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
);
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.
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.
552 SetScrollInfo(SB_VERT
, &sinfo
);
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
));
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());
573 bool bControl
= !!(GetKeyState(VK_CONTROL
)&0x8000);
574 bool bOverview
= m_bShowOverview
&& m_OverviewRect
.PtInRect(point
);
578 const CRevisionGraphState::SVisibleGlyph
* hitGlyph
579 = GetHitGlyph (point
);
583 ToggleNodeFlag (hitGlyph
->node
, hitGlyph
->state
);
584 return __super::OnLButtonDown(nFlags
, point
);
587 node nodeIndex
= GetHitNode (point
);
592 if (m_SelectedEntry1
== nodeIndex
)
594 if (m_SelectedEntry2
)
596 m_SelectedEntry1
= m_SelectedEntry2
;
597 m_SelectedEntry2
= nullptr;
600 m_SelectedEntry1
= nullptr;
602 else if (m_SelectedEntry2
== nodeIndex
)
603 m_SelectedEntry2
= nullptr;
604 else if (m_SelectedEntry1
)
605 m_SelectedEntry2
= nodeIndex
;
607 m_SelectedEntry1
= nodeIndex
;
611 if (m_SelectedEntry1
== nodeIndex
)
612 m_SelectedEntry1
= nullptr;
614 m_SelectedEntry1
= nodeIndex
;
615 m_SelectedEntry2
= nullptr;
622 if ((!bHit
)&&(!bControl
)&&(!bOverview
))
624 m_SelectedEntry1
= nullptr;
625 m_SelectedEntry2
= nullptr;
626 m_bIsCanvasMove
= true;
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
;
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
;
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;
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
680 __super::OnLButtonUp(nFlags
, point
);
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
698 __super::OnLButtonUp(nFlags
, point
);
701 if (fZoomfactor
> MAX_ZOOM
)
703 fZoomfactor
= MAX_ZOOM
;
704 fact
= fZoomfactor
/m_fZoomFactor
;
707 auto pDlg
= static_cast<CRevisionGraphDlg
*>(GetParent());
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
;
723 m_bIsCanvasMove
= false;
724 m_ptRubberEnd
= CPoint(0,0);
728 INT_PTR
CRevisionGraphWnd::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
730 if (IsUpdateJobRunning())
733 node nodeIndex
= GetHitNode (point
);
734 if (m_tooltipIndex
!= nodeIndex
)
736 // force tooltip to be updated
738 m_tooltipIndex
= nodeIndex
;
745 // if ((GetHoverGlyphs (point) != 0) || (GetHitGlyph (point) != nullptr))
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
;
757 BOOL
CRevisionGraphWnd::OnToolTipNotify(UINT
/*id*/, NMHDR
*pNMHDR
, LRESULT
*pResult
)
759 if (pNMHDR
->idFrom
!= (UINT_PTR
)m_hWnd
)
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
));
771 if (strTipText
.IsEmpty())
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);
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()
803 int screenWidth
= GetSystemMetrics(SM_CXSCREEN
);
804 int screenHeight
= GetSystemMetrics(SM_CYSCREEN
);
806 // get current mouse position
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
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
)
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
" ..."
840 // select the tooltip font
842 NONCLIENTMETRICS metrics
;
843 metrics
.cbSize
= sizeof (metrics
);
844 SystemParametersInfo (SPI_GETNONCLIENTMETRICS
, metrics
.cbSize
, &metrics
, 0);
847 font
.CreateFontIndirect(&metrics
.lfStatusFont
);
848 CFont
* pOldFont
= dc
->SelectObject (&font
);
850 // split into lines and fill the tooltip rect
854 int remainingHeight
= tooltipSize
.cy
;
856 while (pos
< wholeText
.GetLength())
858 // extract a whole line
860 int nextPos
= wholeText
.Find ('\n', pos
);
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 (' ');
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
)
892 pos
+= line
.GetLength();
895 // relase temp. resources
897 dc
->SelectObject (pOldFont
);
905 CString
CRevisionGraphWnd::TooltipText(node index
)
910 CGitHash hash
= m_logEntries
[index
->index()];
911 GitRevLoglist
* rev
= this->m_LogCache
.GetCacheData(hash
);
912 str
+= rev
->m_CommitHash
.ToString();
914 str
+= rev
->GetAuthorName() + L
' ' + rev
->GetAuthorEmail();
916 str
+= rev
->GetAuthorDate().Format(L
"%Y-%m-%d %H:%M");
917 str
+= L
"\n\n" + rev
->GetSubject();
919 str
+= rev
->GetBody();
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
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
);
937 rect
= GetViewRect();
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
950 float fZoom
= m_fZoomFactor
;
951 m_fZoomFactor
= DEFAULT_ZOOM
;
952 DoZoom(m_fZoomFactor
);
954 rect
= GetViewRect();
955 svg
.SetViewSize(rect
.Width(), rect
.Height());
958 DrawGraph(dev
, rect
, 0, 0, true);
960 m_fZoomFactor
= fZoom
;
961 DoZoom(m_fZoomFactor
);
963 else if (extension
.CompareNoCase(L
".gv") == 0)
966 float fZoom
= m_fZoomFactor
;
967 m_fZoomFactor
= DEFAULT_ZOOM
;
968 DoZoom(m_fZoomFactor
);
970 rect
= GetViewRect();
972 dev
.pGraphviz
= &graphviz
;
973 DrawGraph(dev
, rect
, 0, 0, true);
974 graphviz
.Save(sSavePath
);
975 m_fZoomFactor
= fZoom
;
976 DoZoom(m_fZoomFactor
);
980 // save the graph as a pixel picture instead of a vector picture
981 // create dc to paint on
984 CString sErrormessage
;
987 if (!dc
.CreateCompatibleDC(&ddc
))
989 CFormatMessageWrapper errorDetails
;
991 MessageBox(errorDetails
, L
"Error", MB_OK
| MB_ICONINFORMATION
);
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 };
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);
1014 CMessageBox::Show(m_hWnd
, IDS_REVGRAPH_ERR_NOMEMORY
, IDS_APPNAME
, MB_ICONERROR
);
1017 HBITMAP oldbm
= (HBITMAP
)dc
.SelectObject(hbm
);
1018 // paint the whole graph
1021 DrawGraph(dev
, rect
, 0, 0, true);
1022 // now use GDI+ to save the picture
1025 Bitmap
bitmap(hbm
, nullptr);
1026 if (bitmap
.GetLastStatus()==Ok
)
1028 // Get the CLSID of the encoder.
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
);
1042 sSavePath
+= L
".jpg";
1043 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1047 CStringW tfile
= CStringW(sSavePath
);
1048 bitmap
.Save(tfile
, &encoderClsid
, nullptr);
1051 sErrormessage
.Format(IDS_REVGRAPH_ERR_NOENCODER
, (LPCTSTR
)CPathUtils::GetFileExtFromPath(sSavePath
));
1054 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_NOBITMAP
);
1056 dc
.SelectObject(oldbm
);
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);
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
)));
1084 int orientation
= (GetKeyState(VK_SHIFT
) & 0x8000) ? SB_HORZ
: SB_VERT
;
1085 int pos
= GetScrollPos(orientation
);
1087 SetScrollPos(orientation
, pos
);
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
);
1101 SetScrollPos(orientation
, pos
);
1104 return __super::OnMouseHWheel(nFlags
, zDelta
, pt
);
1107 bool CRevisionGraphWnd::UpdateSelectedEntry (node clickedentry
)
1109 if (!m_SelectedEntry1
&& !clickedentry
)
1112 if (!m_SelectedEntry1
)
1114 m_SelectedEntry1
= clickedentry
;
1117 if (!m_SelectedEntry2
&& clickedentry
!= m_SelectedEntry1
)
1119 m_SelectedEntry1
= clickedentry
;
1122 if (m_SelectedEntry1
&& m_SelectedEntry2
)
1124 if ((m_SelectedEntry2
!= clickedentry
)&&(m_SelectedEntry1
!= clickedentry
))
1127 if (!m_SelectedEntry1
)
1133 void CRevisionGraphWnd::AppendMenu
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);
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*/)
1180 CSyncPointer
<CGraphNodeStates
> nodeStates (m_state
.GetNodeStates());
1184 DWORD state
= nodeStates
->GetCombinedFlags();
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
);
1196 DWORD state
= nodeStates
->GetFlags (node
);
1198 if (node
->GetSource() || (state
& CGraphNodeStates::COLLAPSED_ABOVE
))
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
))
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
))
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
))
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
))
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
))
1235 , (state
& CGraphNodeStates::SPLIT_BELOW
)
1236 ? IDS_REVGRAPH_POPUP_JOIN_BELOW
1237 : IDS_REVGRAPH_POPUP_SPLIT_BELOW
1238 , ID_GRAPH_SPLITJOIN_BELOW
);
1243 CString
CRevisionGraphWnd::GetSelectedURL() const
1246 if (!m_SelectedEntry1
)
1249 CString URL
= m_state
.GetRepositoryRoot()
1250 + CUnicodeUtils::GetUnicode (m_SelectedEntry1
->GetPath().GetPath().c_str());
1251 URL
= CUnicodeUtils::GetUnicode(CPathUtils::PathEscape(CUnicodeUtils::GetUTF8(URL
)));
1258 CString
CRevisionGraphWnd::GetWCURL() const
1261 CTGitPath
path (m_sPath
);
1266 const SVNInfoData
* status
1267 = info
.GetFirstFileInfo (path
, SVNRev(), SVNRev());
1269 return !status
? CString() : status
->url
;
1274 void CRevisionGraphWnd::DoShowLog()
1276 if (!m_SelectedEntry1
)
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());
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()
1297 dlg
.m_pathList
= CTGitPathList (CTGitPath (m_sPath
));
1301 void CRevisionGraphWnd::DoMergeTo()
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
)));
1314 dlg
.SetSecondUrl(URL
);
1315 SVNRevRangeArray revarray
;
1316 revarray
.AddRevRange (m_SelectedEntry1
->GetRevision()-1, svn_revnum_t(m_SelectedEntry1
->GetRevision()));
1317 dlg
.SetRevisionRanges(revarray
);
1323 void CRevisionGraphWnd::DoUpdate()
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());
1334 if (m_state
.GetFetchedWCState())
1335 m_parent
->UpdateFullHistory();
1339 void CRevisionGraphWnd::DoSwitch(CString rev
)
1341 CAppUtils::PerformSwitch(rev
);
1344 void CRevisionGraphWnd::DoSwitchToHead()
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());
1355 if (m_state
.GetFetchedWCState())
1356 m_parent
->UpdateFullHistory();
1360 void CRevisionGraphWnd::DoBrowseRepo()
1362 if (!m_SelectedEntry1
)
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*/)
1382 CSyncPointer
<CGraphNodeStates
> nodeStates (m_state
.GetNodeStates());
1384 if (nodeStates
->GetFlags (node
) & flag
)
1385 nodeStates
->ResetFlags (node
, flag
);
1387 nodeStates
->SetFlags (node
, flag
);
1389 m_parent
->StartWorkerThread();
1393 void CRevisionGraphWnd::DoCopyRefs()
1395 if (!m_SelectedEntry1
)
1398 STRING_VECTOR list
= GetFriendRefNames(m_SelectedEntry1
);
1401 text
= m_logEntries
[m_SelectedEntry1
->index()].ToString();
1402 for (size_t i
= 0; i
< list
.size(); ++i
)
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())
1416 CPoint clientpoint
= point
;
1417 this->ScreenToClient(&clientpoint
);
1419 node nodeIndex
= GetHitNode (clientpoint
);
1421 if ( !UpdateSelectedEntry (nodeIndex
))
1425 if (!popup
.CreatePopupMenu())
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)
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)
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
);
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
)
1489 case ID_UNIDIFFREVS
:
1490 if (m_SelectedEntry1
)
1491 UnifiedDiffRevs(false);
1493 case ID_UNIDIFFHEADS
:
1494 if (m_SelectedEntry1
)
1495 UnifiedDiffRevs(true);
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
;
1510 m_parent
->UpdateFullHistory();
1520 case ID_COMPAREHEADS
:
1521 if (m_SelectedEntry1
)
1522 CompareRevs(L
"HEAD");
1525 if (m_SelectedEntry1
)
1526 CompareRevs(CGitHash().ToString());
1530 case ID_COMPAREREVS
:
1531 if (m_SelectedEntry1
)
1534 case ID_UNIDIFFREVS
:
1535 if (m_SelectedEntry1
)
1536 UnifiedDiffRevs(false);
1538 case ID_UNIDIFFHEADS
:
1539 if (m_SelectedEntry1
)
1540 UnifiedDiffRevs(true);
1546 DoCheckForModification();
1554 case ID_SWITCHTOHEAD
:
1558 ResetNodeFlags (CGraphNodeStates::COLLAPSED_ALL
);
1561 ResetNodeFlags (CGraphNodeStates::SPLIT_ALL
);
1563 case ID_GRAPH_EXPANDCOLLAPSE_ABOVE
:
1564 ToggleNodeFlag (clickedentry
, CGraphNodeStates::COLLAPSED_ABOVE
);
1566 case ID_GRAPH_EXPANDCOLLAPSE_RIGHT
:
1567 ToggleNodeFlag (clickedentry
, CGraphNodeStates::COLLAPSED_RIGHT
);
1569 case ID_GRAPH_EXPANDCOLLAPSE_BELOW
:
1570 ToggleNodeFlag (clickedentry
, CGraphNodeStates::COLLAPSED_BELOW
);
1572 case ID_GRAPH_SPLITJOIN_ABOVE
:
1573 ToggleNodeFlag (clickedentry
, CGraphNodeStates::SPLIT_ABOVE
);
1575 case ID_GRAPH_SPLITJOIN_RIGHT
:
1576 ToggleNodeFlag (clickedentry
, CGraphNodeStates::SPLIT_RIGHT
);
1578 case ID_GRAPH_SPLITJOIN_BELOW
:
1579 ToggleNodeFlag (clickedentry
, CGraphNodeStates::SPLIT_BELOW
);
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
))
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
);
1598 SetScrollbars(y
, x
);
1600 return __super::OnMouseMove(nFlags
, point
);
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
);
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);
1627 && ( (m_hoverIndex
!= GetHitNode (clientPoint
))))
1629 m_showHoverGlyphs
= false;
1631 KillTimer (GLYPH_HOVER_EVENT
);
1632 SetTimer(GLYPH_HOVER_EVENT
, GLYPH_HOVER_DELAY
, nullptr);
1637 return __super::OnMouseMove(nFlags
, point
);
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
;
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
))
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
)
1689 void CRevisionGraphWnd::OnTimer (UINT_PTR nIDEvent
)
1691 if (nIDEvent
== GLYPH_HOVER_EVENT
)
1693 KillTimer (GLYPH_HOVER_EVENT
);
1695 m_showHoverGlyphs
= true;
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();
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
);
1731 if (m_parent
&& !m_parent
->GetOutputFile().IsEmpty())
1733 // save the graph to the output file and exit
1734 SaveGraphAs(m_parent
->GetOutputFile());
1740 void CRevisionGraphWnd::SetDlgTitle (bool /*offline*/)
1743 if (m_sTitle
.IsEmpty())
1744 GetParent()->GetWindowText(m_sTitle
);
1748 newTitle
.Format (IDS_REVGRAPH_DLGTITLEOFFLINE
, (LPCTSTR
)m_sTitle
);
1750 newTitle
= m_sTitle
;
1752 CAppUtils::SetWindowTitle(GetParent()->GetSafeHwnd(), m_sPath
, newTitle
);