1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2012 - TortoiseSVN
4 // Copyright (C) 2012-2014 - 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"
38 #include "FormatMessageWrapper.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(NULL
)
88 , m_SelectedEntry2(NULL
)
92 , m_bTweakTrunkColors(true)
93 , m_bTweakTagsColors(true)
94 , m_fZoomFactor(DEFAULT_ZOOM
)
97 , m_bShowOverview(false)
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
, (CFont
*)NULL
);
116 HINSTANCE hInst
= AfxGetInstanceHandle();
117 #define REVGRAPH_CLASSNAME _T("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
;
126 wndcls
.hCursor
= AfxGetApp()->LoadStandardCursor(IDC_ARROW
);
127 wndcls
.hbrBackground
= (HBRUSH
) (COLOR_WINDOW
+ 1);
128 wndcls
.lpszMenuName
= NULL
;
129 wndcls
.lpszClassName
= REVGRAPH_CLASSNAME
;
131 RegisterClass(&wndcls
);
134 m_bTweakTrunkColors
= CRegDWORD(_T("Software\\TortoiseGit\\RevisionGraph\\TweakTrunkColors"), TRUE
) != FALSE
;
135 m_bTweakTagsColors
= CRegDWORD(_T("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
) {
217 TRACE(_T("node x %f y %f %f %f\n"),/* m_GraphAttr.idNode(v), */
220 m_GraphAttr
.width(v
),
221 m_GraphAttr
.height(v
)
226 forall_edges(e
, m_Graph
)
228 // get connection and point position
229 const DPolyline
&dpl
= this->m_GraphAttr
.bends(e
);
231 ListConstIterator
<DPoint
> it
;
232 for(it
= dpl
.begin(); it
.valid(); ++it
)
234 TRACE(_T("edge %f %f\n"), (*it
).m_x
, (*it
).m_y
);
237 m_GraphAttr
.writeGML("test.gml");
241 CRevisionGraphWnd::~CRevisionGraphWnd()
243 for (int i
= 0; i
< MAXFONTS
; ++i
)
245 if (m_apFonts
[i
] != NULL
)
247 m_apFonts
[i
]->DeleteObject();
256 void CRevisionGraphWnd::DoDataExchange(CDataExchange
* pDX
)
258 CWnd::DoDataExchange(pDX
);
262 BEGIN_MESSAGE_MAP(CRevisionGraphWnd
, CWnd
)
269 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, OnToolTipNotify
)
270 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, OnToolTipNotify
)
278 ON_MESSAGE(WM_WORKERTHREADDONE
,OnWorkerThreadDone
)
279 ON_WM_CAPTURECHANGED()
282 void CRevisionGraphWnd::Init(CWnd
* pParent
, LPRECT rect
)
285 HINSTANCE hInst
= AfxGetInstanceHandle();
286 #define REVGRAPH_CLASSNAME _T("Revgraph_windowclass")
287 if (!(::GetClassInfo(hInst
, REVGRAPH_CLASSNAME
, &wndcls
)))
289 // otherwise we need to register a new class
290 wndcls
.style
= CS_DBLCLKS
| CS_OWNDC
;
291 wndcls
.lpfnWndProc
= ::DefWindowProc
;
292 wndcls
.cbClsExtra
= wndcls
.cbWndExtra
= 0;
293 wndcls
.hInstance
= hInst
;
295 wndcls
.hCursor
= AfxGetApp()->LoadStandardCursor(IDC_ARROW
);
296 wndcls
.hbrBackground
= (HBRUSH
) (COLOR_WINDOW
+ 1);
297 wndcls
.lpszMenuName
= NULL
;
298 wndcls
.lpszClassName
= REVGRAPH_CLASSNAME
;
300 RegisterClass(&wndcls
);
303 if (!IsWindow(m_hWnd
))
304 CreateEx(WS_EX_CLIENTEDGE
, REVGRAPH_CLASSNAME
, _T("RevGraph"), WS_CHILD
|WS_VISIBLE
|WS_TABSTOP
, *rect
, pParent
, 0);
305 m_pDlgTip
= new CToolTipCtrl
;
306 if(!m_pDlgTip
->Create(this))
308 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Unable to add tooltip!\n");
312 memset(&m_lfBaseFont
, 0, sizeof(m_lfBaseFont
));
313 m_lfBaseFont
.lfHeight
= 0;
314 m_lfBaseFont
.lfWeight
= FW_NORMAL
;
315 m_lfBaseFont
.lfItalic
= FALSE
;
316 m_lfBaseFont
.lfCharSet
= DEFAULT_CHARSET
;
317 m_lfBaseFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
318 m_lfBaseFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
319 m_lfBaseFont
.lfQuality
= DEFAULT_QUALITY
;
320 m_lfBaseFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
322 m_dwTicks
= GetTickCount();
324 m_parent
= dynamic_cast<CRevisionGraphDlg
*>(pParent
);
327 CPoint
CRevisionGraphWnd::GetLogCoordinates (CPoint point
) const
329 // translate point into logical coordinates
331 int nVScrollPos
= GetScrollPos(SB_VERT
);
332 int nHScrollPos
= GetScrollPos(SB_HORZ
);
334 return CPoint ( (int)((point
.x
+ nHScrollPos
) / m_fZoomFactor
)
335 , (int)((point
.y
+ nVScrollPos
) / m_fZoomFactor
));
338 node
CRevisionGraphWnd::GetHitNode (CPoint point
, CSize
/*border*/) const
343 CSyncPointer
<const ILayoutNodeList
> nodeList (m_state
.GetNodes());
345 return index_t(NO_INDEX
);
347 // search the nodes for one at that grid position
349 return nodeList
->GetAt (GetLogCoordinates (point
), border
);
353 forall_nodes(v
,m_Graph
)
355 RectF
noderect (GetNodeRect (v
, CPoint(GetScrollPos(SB_HORZ
), GetScrollPos(SB_VERT
))));
356 if(point
.x
>noderect
.X
&& point
.x
<(noderect
.X
+noderect
.Width
) &&
357 point
.y
>noderect
.Y
&& point
.y
<(noderect
.Y
+noderect
.Height
))
365 DWORD
CRevisionGraphWnd::GetHoverGlyphs (CPoint
/*point*/) const
367 // if there is no layout, there will be no nodes,
371 CSyncPointer
<const ILayoutNodeList
> nodeList (m_state
.GetNodes());
375 // get node at point or node that is close enough
376 // so that point may hit a glyph area
378 index_t nodeIndex
= GetHitNode(point
);
379 if (nodeIndex
== NO_INDEX
)
380 nodeIndex
= GetHitNode(point
, CSize (GLYPH_SIZE
, GLYPH_SIZE
/ 2));
382 if (nodeIndex
>= nodeList
->GetCount())
385 ILayoutNodeList::SNode node
= nodeList
->GetNode (nodeIndex
);
386 const CVisibleGraphNode
* base
= node
.node
;
388 // what glyphs should be shown depending on position of point
389 // relative to the node rect?
391 CPoint logCoordinates
= GetLogCoordinates (point
);
393 CPoint center
= r
.CenterPoint();
395 CRect
rightGlyphArea ( r
.right
- GLYPH_SIZE
, center
.y
- GLYPH_SIZE
/ 2
396 , r
.right
+ GLYPH_SIZE
, center
.y
+ GLYPH_SIZE
/ 2);
397 CRect
topGlyphArea ( center
.x
- GLYPH_SIZE
, r
.top
- GLYPH_SIZE
/ 2
398 , center
.x
+ GLYPH_SIZE
, r
.top
+ GLYPH_SIZE
/ 2);
399 CRect
bottomGlyphArea ( center
.x
- GLYPH_SIZE
, r
.bottom
- GLYPH_SIZE
/ 2
400 , center
.x
+ GLYPH_SIZE
, r
.bottom
+ GLYPH_SIZE
/ 2);
403 = m_state
.GetOptions()->GetOption
<CUpsideDownLayout
>()->IsActive();
407 std::swap (topGlyphArea
.top
, bottomGlyphArea
.top
);
408 std::swap (topGlyphArea
.bottom
, bottomGlyphArea
.bottom
);
412 if (rightGlyphArea
.PtInRect (logCoordinates
))
413 result
= base
->GetFirstCopyTarget() != NULL
414 ? CGraphNodeStates::COLLAPSED_RIGHT
| CGraphNodeStates::SPLIT_RIGHT
417 if (topGlyphArea
.PtInRect (logCoordinates
))
418 result
= base
->GetSource() != NULL
419 ? CGraphNodeStates::COLLAPSED_ABOVE
| CGraphNodeStates::SPLIT_ABOVE
422 if (bottomGlyphArea
.PtInRect (logCoordinates
))
423 result
= base
->GetNext() != NULL
424 ? CGraphNodeStates::COLLAPSED_BELOW
| CGraphNodeStates::SPLIT_BELOW
427 // if some nodes have already been split, don't allow collapsing etc.
429 CSyncPointer
<const CGraphNodeStates
> nodeStates (m_state
.GetNodeStates());
430 if (result
& nodeStates
->GetFlags (base
))
436 const CRevisionGraphState::SVisibleGlyph
* CRevisionGraphWnd::GetHitGlyph (CPoint point
) const
438 float glyphSize
= GLYPH_SIZE
* m_fZoomFactor
;
440 CSyncPointer
<const CRevisionGraphState::TVisibleGlyphs
>
441 visibleGlyphs (m_state
.GetVisibleGlyphs());
443 for (size_t i
= 0, count
= visibleGlyphs
->size(); i
< count
; ++i
)
445 const CRevisionGraphState::SVisibleGlyph
* entry
= &(*visibleGlyphs
)[i
];
447 float xRel
= point
.x
- entry
->leftTop
.X
;
448 float yRel
= point
.y
- entry
->leftTop
.Y
;
450 if ( (xRel
>= 0) && (xRel
< glyphSize
)
451 && (yRel
>= 0) && (yRel
< glyphSize
))
460 void CRevisionGraphWnd::OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
462 SCROLLINFO sinfo
= {0};
463 sinfo
.cbSize
= sizeof(SCROLLINFO
);
464 GetScrollInfo(SB_HORZ
, &sinfo
);
466 // Determine the new position of scroll box.
469 case SB_LEFT
: // Scroll to far left.
470 sinfo
.nPos
= sinfo
.nMin
;
472 case SB_RIGHT
: // Scroll to far right.
473 sinfo
.nPos
= sinfo
.nMax
;
475 case SB_ENDSCROLL
: // End scroll.
477 case SB_LINELEFT
: // Scroll left.
478 if (sinfo
.nPos
> sinfo
.nMin
)
481 case SB_LINERIGHT
: // Scroll right.
482 if (sinfo
.nPos
< sinfo
.nMax
)
485 case SB_PAGELEFT
: // Scroll one page left.
487 if (sinfo
.nPos
> sinfo
.nMin
)
488 sinfo
.nPos
= max(sinfo
.nMin
, sinfo
.nPos
- (int) sinfo
.nPage
);
491 case SB_PAGERIGHT
: // Scroll one page right.
493 if (sinfo
.nPos
< sinfo
.nMax
)
494 sinfo
.nPos
= min(sinfo
.nMax
, sinfo
.nPos
+ (int) sinfo
.nPage
);
497 case SB_THUMBPOSITION
: // Scroll to absolute position. nPos is the position
498 sinfo
.nPos
= sinfo
.nTrackPos
; // of the scroll box at the end of the drag operation.
500 case SB_THUMBTRACK
: // Drag scroll box to specified position. nPos is the
501 sinfo
.nPos
= sinfo
.nTrackPos
; // position that the scroll box has been dragged to.
504 SetScrollInfo(SB_HORZ
, &sinfo
);
506 __super::OnHScroll(nSBCode
, nPos
, pScrollBar
);
509 void CRevisionGraphWnd::OnVScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
511 SCROLLINFO sinfo
= {0};
512 sinfo
.cbSize
= sizeof(SCROLLINFO
);
513 GetScrollInfo(SB_VERT
, &sinfo
);
515 // Determine the new position of scroll box.
518 case SB_LEFT
: // Scroll to far left.
519 sinfo
.nPos
= sinfo
.nMin
;
521 case SB_RIGHT
: // Scroll to far right.
522 sinfo
.nPos
= sinfo
.nMax
;
524 case SB_ENDSCROLL
: // End scroll.
526 case SB_LINELEFT
: // Scroll left.
527 if (sinfo
.nPos
> sinfo
.nMin
)
530 case SB_LINERIGHT
: // Scroll right.
531 if (sinfo
.nPos
< sinfo
.nMax
)
534 case SB_PAGELEFT
: // Scroll one page left.
536 if (sinfo
.nPos
> sinfo
.nMin
)
537 sinfo
.nPos
= max(sinfo
.nMin
, sinfo
.nPos
- (int) sinfo
.nPage
);
540 case SB_PAGERIGHT
: // Scroll one page right.
542 if (sinfo
.nPos
< sinfo
.nMax
)
543 sinfo
.nPos
= min(sinfo
.nMax
, sinfo
.nPos
+ (int) sinfo
.nPage
);
546 case SB_THUMBPOSITION
: // Scroll to absolute position. nPos is the position
547 sinfo
.nPos
= sinfo
.nTrackPos
; // of the scroll box at the end of the drag operation.
549 case SB_THUMBTRACK
: // Drag scroll box to specified position. nPos is the
550 sinfo
.nPos
= sinfo
.nTrackPos
; // position that the scroll box has been dragged to.
553 SetScrollInfo(SB_VERT
, &sinfo
);
555 __super::OnVScroll(nSBCode
, nPos
, pScrollBar
);
558 void CRevisionGraphWnd::OnSize(UINT nType
, int cx
, int cy
)
560 __super::OnSize(nType
, cx
, cy
);
561 SetScrollbars(GetScrollPos(SB_VERT
), GetScrollPos(SB_HORZ
));
565 void CRevisionGraphWnd::OnLButtonDown(UINT nFlags
, CPoint point
)
568 if (IsUpdateJobRunning())
569 return __super::OnLButtonDown(nFlags
, point
);
571 // CSyncPointer<const ILayoutNodeList> nodeList (m_state.GetNodes());
575 bool bControl
= !!(GetKeyState(VK_CONTROL
)&0x8000);
576 bool bOverview
= m_bShowOverview
&& m_OverviewRect
.PtInRect(point
);
580 const CRevisionGraphState::SVisibleGlyph
* hitGlyph
581 = GetHitGlyph (point
);
583 if (hitGlyph
!= NULL
)
585 ToggleNodeFlag (hitGlyph
->node
, hitGlyph
->state
);
586 return __super::OnLButtonDown(nFlags
, point
);
589 node nodeIndex
= GetHitNode (point
);
590 if (nodeIndex
!= NULL
)
594 if (m_SelectedEntry1
== nodeIndex
)
596 if (m_SelectedEntry2
)
598 m_SelectedEntry1
= m_SelectedEntry2
;
599 m_SelectedEntry2
= NULL
;
602 m_SelectedEntry1
= NULL
;
604 else if (m_SelectedEntry2
== nodeIndex
)
605 m_SelectedEntry2
= NULL
;
606 else if (m_SelectedEntry1
)
607 m_SelectedEntry2
= nodeIndex
;
609 m_SelectedEntry1
= nodeIndex
;
613 if (m_SelectedEntry1
== nodeIndex
)
614 m_SelectedEntry1
= NULL
;
616 m_SelectedEntry1
= nodeIndex
;
617 m_SelectedEntry2
= NULL
;
624 if ((!bHit
)&&(!bControl
)&&(!bOverview
))
626 m_SelectedEntry1
= NULL
;
627 m_SelectedEntry2
= NULL
;
628 m_bIsCanvasMove
= true;
630 if (m_bShowOverview
&& m_OverviewRect
.PtInRect(point
))
631 m_bIsCanvasMove
= false;
633 m_ptMoveCanvas
= point
;
635 UINT uEnable
= MF_BYCOMMAND
;
636 if ((m_SelectedEntry1
!= NULL
)&&(m_SelectedEntry2
!= NULL
))
637 uEnable
|= MF_ENABLED
;
639 uEnable
|= MF_GRAYED
;
641 EnableMenuItem(GetParent()->GetMenu()->m_hMenu
, ID_VIEW_COMPAREREVISIONS
, uEnable
);
642 EnableMenuItem(GetParent()->GetMenu()->m_hMenu
, ID_VIEW_UNIFIEDDIFF
, uEnable
);
644 uEnable
= MF_BYCOMMAND
;
645 if ((m_SelectedEntry1
!= NULL
)&&(m_SelectedEntry2
== NULL
))
646 uEnable
|= MF_ENABLED
;
648 uEnable
|= MF_GRAYED
;
650 EnableMenuItem(GetParent()->GetMenu()->m_hMenu
, ID_VIEW_UNIFIEDDIFFOFHEADREVISIONS
, uEnable
);
651 EnableMenuItem(GetParent()->GetMenu()->m_hMenu
, ID_VIEW_COMPAREHEADREVISIONS
, uEnable
);
653 __super::OnLButtonDown(nFlags
, point
);
656 void CRevisionGraphWnd::OnCaptureChanged(CWnd
*pWnd
)
658 __super::OnCaptureChanged(pWnd
);
661 void CRevisionGraphWnd::OnLButtonUp(UINT nFlags
, CPoint point
)
663 if (!m_bIsCanvasMove
)
664 return; // we don't have a rubberband, so no zooming necessary
666 m_bIsCanvasMove
= false;
668 if (IsUpdateJobRunning())
669 return __super::OnLButtonUp(nFlags
, point
);
671 // zooming is finished
672 m_ptRubberEnd
= CPoint(0,0);
673 CRect rect
= GetClientRect();
674 int x
= abs(m_ptMoveCanvas
.x
- point
.x
);
675 int y
= abs(m_ptMoveCanvas
.y
- point
.y
);
677 if ((x
< 20)&&(y
< 20))
679 // too small zoom rectangle
680 // assume zooming by accident
682 __super::OnLButtonUp(nFlags
, point
);
686 float xfact
= float(rect
.Width())/float(x
);
687 float yfact
= float(rect
.Height())/float(y
);
688 float fact
= max(yfact
, xfact
);
690 // find out where to scroll to
691 x
= min(m_ptMoveCanvas
.x
, point
.x
) + GetScrollPos(SB_HORZ
);
692 y
= min(m_ptMoveCanvas
.y
, point
.y
) + GetScrollPos(SB_VERT
);
694 float fZoomfactor
= m_fZoomFactor
*fact
;
695 if (fZoomfactor
> 10 * MAX_ZOOM
)
697 // with such a big zoomfactor, the user
698 // most likely zoomed by accident
700 __super::OnLButtonUp(nFlags
, point
);
703 if (fZoomfactor
> MAX_ZOOM
)
705 fZoomfactor
= MAX_ZOOM
;
706 fact
= fZoomfactor
/m_fZoomFactor
;
709 CRevisionGraphDlg
* pDlg
= (CRevisionGraphDlg
*)GetParent();
712 m_fZoomFactor
= fZoomfactor
;
713 pDlg
->DoZoom (m_fZoomFactor
);
714 SetScrollbars(int(float(y
)*fact
), int(float(x
)*fact
));
716 __super::OnLButtonUp(nFlags
, point
);
719 bool CRevisionGraphWnd::CancelMouseZoom()
721 bool bRet
= m_bIsCanvasMove
;
725 m_bIsCanvasMove
= false;
726 m_ptRubberEnd
= CPoint(0,0);
730 INT_PTR
CRevisionGraphWnd::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
733 if (IsUpdateJobRunning())
736 node nodeIndex
= GetHitNode (point
);
737 if (m_tooltipIndex
!= nodeIndex
)
739 // force tooltip to be updated
741 m_tooltipIndex
= nodeIndex
;
745 if (nodeIndex
== NULL
)
748 // if ((GetHoverGlyphs (point) != 0) || (GetHitGlyph (point) != NULL))
751 pTI
->hwnd
= this->m_hWnd
;
752 CWnd::GetClientRect(&pTI
->rect
);
753 pTI
->uFlags
|= TTF_ALWAYSTIP
| TTF_IDISHWND
;
754 pTI
->uId
= (UINT_PTR
)m_hWnd
;
755 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
760 BOOL
CRevisionGraphWnd::OnToolTipNotify(UINT
/*id*/, NMHDR
*pNMHDR
, LRESULT
*pResult
)
762 if (pNMHDR
->idFrom
!= (UINT_PTR
)m_hWnd
)
766 DWORD ptW
= GetMessagePos();
767 point
.x
= GET_X_LPARAM(ptW
);
768 point
.y
= GET_Y_LPARAM(ptW
);
769 ScreenToClient(&point
);
771 CString strTipText
= TooltipText (GetHitNode (point
));
774 if (strTipText
.IsEmpty())
777 CSize tooltipSize
= UsableTooltipRect();
778 strTipText
= DisplayableText (strTipText
, tooltipSize
);
780 // need to handle both ANSI and UNICODE versions of the message
781 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
783 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
784 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, tooltipSize
.cx
);
785 pTTTA
->lpszText
= m_szTip
;
786 WideCharToMultiByte(CP_ACP
, 0, strTipText
, -1, m_szTip
, strTipText
.GetLength()+1, 0, 0);
790 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
791 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, tooltipSize
.cx
);
792 lstrcpyn(m_wszTip
, strTipText
, strTipText
.GetLength()+1);
793 pTTTW
->lpszText
= m_wszTip
;
796 // show the tooltip for 32 seconds. A higher value than 32767 won't work
797 // even though it's nowhere documented!
798 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETDELAYTIME
, TTDT_AUTOPOP
, 32767);
799 return TRUE
; // message was handled
802 CSize
CRevisionGraphWnd::UsableTooltipRect()
806 int screenWidth
= GetSystemMetrics(SM_CXSCREEN
);
807 int screenHeight
= GetSystemMetrics(SM_CYSCREEN
);
809 // get current mouse position
812 if (GetCursorPos (&cursorPos
) == FALSE
)
814 // we could not determine the mouse position
815 // use screen / 2 minus some safety margin
817 return CSize (screenWidth
/ 2 - 20, screenHeight
/ 2 - 20);
820 // tool tip will display in the biggest sector beside the cursor
821 // deduct some safety margin (for the mouse cursor itself
824 ( max (screenWidth
- cursorPos
.x
- 40, cursorPos
.x
- 24)
825 , max (screenHeight
- cursorPos
.y
- 40, cursorPos
.y
- 24));
827 return biggestSector
;
830 CString
CRevisionGraphWnd::DisplayableText ( const CString
& wholeText
831 , const CSize
& tooltipSize
)
836 // no access to the device context -> truncate hard at 1000 chars
838 return wholeText
.GetLength() >= MAX_TT_LENGTH_DEFAULT
839 ? wholeText
.Left (MAX_TT_LENGTH_DEFAULT
-4) + _T(" ...")
843 // select the tooltip font
845 NONCLIENTMETRICS metrics
;
846 metrics
.cbSize
= sizeof (metrics
);
847 if (!SysInfo::Instance().IsVistaOrLater())
849 metrics
.cbSize
-= sizeof(int); // subtract the size of the iPaddedBorderWidth member which is not available on XP
851 SystemParametersInfo (SPI_GETNONCLIENTMETRICS
, metrics
.cbSize
, &metrics
, 0);
854 font
.CreateFontIndirect(&metrics
.lfStatusFont
);
855 CFont
* pOldFont
= dc
->SelectObject (&font
);
857 // split into lines and fill the tooltip rect
861 int remainingHeight
= tooltipSize
.cy
;
863 while (pos
< wholeText
.GetLength())
865 // extract a whole line
867 int nextPos
= wholeText
.Find ('\n', pos
);
869 nextPos
= wholeText
.GetLength();
871 CString line
= wholeText
.Mid (pos
, nextPos
-pos
+1);
873 // find a way to make it fit
875 CSize size
= dc
->GetTextExtent (line
);
876 while (size
.cx
> tooltipSize
.cx
)
878 line
.Delete (line
.GetLength()-1);
879 int nextPos2
= line
.ReverseFind (' ');
883 line
.Delete (nextPos2
+1, line
.GetLength() - pos
-1);
884 size
= dc
->GetTextExtent (line
);
887 // enough room for the new line?
889 remainingHeight
-= size
.cy
;
890 if (remainingHeight
<= size
.cy
)
899 pos
+= line
.GetLength();
902 // relase temp. resources
904 dc
->SelectObject (pOldFont
);
912 CString
CRevisionGraphWnd::TooltipText(node index
)
917 CGitHash hash
= m_logEntries
[index
->index()];
918 GitRev
*rev
= this->m_LogCache
.GetCacheData(hash
);
919 str
+= rev
->m_CommitHash
.ToString();
921 str
+= rev
->GetAuthorName() +_T(" ") + rev
->GetAuthorEmail();
923 str
+= rev
->GetAuthorDate().Format(_T("%Y-%m-%d %H:%M"));
924 str
+= _T("\n\n")+rev
->GetSubject();
926 str
+= rev
->GetBody();
933 void CRevisionGraphWnd::SaveGraphAs(CString sSavePath
)
936 CString extension
= CPathUtils::GetFileExtFromPath(sSavePath
);
937 if (extension
.CompareNoCase(_T(".wmf"))==0)
939 // save the graph as an enhanced metafile
941 wmfDC
.CreateEnhanced(NULL
, sSavePath
, NULL
, _T("TortoiseGit\0Revision Graph\0\0"));
942 float fZoom
= m_fZoomFactor
;
943 m_fZoomFactor
= DEFAULT_ZOOM
;
944 DoZoom(m_fZoomFactor
);
946 rect
= GetViewRect();
949 DrawGraph(dev
, rect
, 0, 0, true);
950 HENHMETAFILE hemf
= wmfDC
.CloseEnhanced();
951 DeleteEnhMetaFile(hemf
);
952 m_fZoomFactor
= fZoom
;
953 DoZoom(m_fZoomFactor
);
955 else if (extension
.CompareNoCase(_T(".svg"))==0)
957 // save the graph as a scalable vector graphic
959 float fZoom
= m_fZoomFactor
;
960 m_fZoomFactor
= DEFAULT_ZOOM
;
961 DoZoom(m_fZoomFactor
);
963 rect
= GetViewRect();
964 svg
.SetViewSize(rect
.Width(), rect
.Height());
967 DrawGraph(dev
, rect
, 0, 0, true);
969 m_fZoomFactor
= fZoom
;
970 DoZoom(m_fZoomFactor
);
972 else if (extension
.CompareNoCase(_T(".gv")) == 0)
975 float fZoom
= m_fZoomFactor
;
976 m_fZoomFactor
= DEFAULT_ZOOM
;
977 DoZoom(m_fZoomFactor
);
979 rect
= GetViewRect();
981 dev
.pGraphviz
= &graphviz
;
982 DrawGraph(dev
, rect
, 0, 0, true);
983 graphviz
.Save(sSavePath
);
984 m_fZoomFactor
= fZoom
;
985 DoZoom(m_fZoomFactor
);
989 // save the graph as a pixel picture instead of a vector picture
990 // create dc to paint on
993 CString sErrormessage
;
996 if (!dc
.CreateCompatibleDC(&ddc
))
998 CFormatMessageWrapper errorDetails
;
1000 MessageBox( errorDetails
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
1005 rect
= GetGraphRect();
1006 rect
.bottom
= (LONG
)(float(rect
.Height()) * m_fZoomFactor
);
1007 rect
.right
= (LONG
)(float(rect
.Width()) * m_fZoomFactor
);
1011 // Initialize header to 0s.
1012 SecureZeroMemory(&bmi
, sizeof(bmi
));
1013 // Fill out the fields you care about.
1014 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1015 bmi
.bmiHeader
.biWidth
= rect
.Width();
1016 bmi
.bmiHeader
.biHeight
= rect
.Height();
1017 bmi
.bmiHeader
.biPlanes
= 1;
1018 bmi
.bmiHeader
.biBitCount
= 24;
1019 bmi
.bmiHeader
.biCompression
= BI_RGB
;
1021 // Create the surface.
1022 hbm
= CreateDIBSection(ddc
.m_hDC
, &bmi
, DIB_RGB_COLORS
,(void **)&pBits
, NULL
, 0);
1025 CMessageBox::Show(m_hWnd
, IDS_REVGRAPH_ERR_NOMEMORY
, IDS_APPNAME
, MB_ICONERROR
);
1028 HBITMAP oldbm
= (HBITMAP
)dc
.SelectObject(hbm
);
1029 // paint the whole graph
1032 DrawGraph(dev
, rect
, 0, 0, true);
1033 // now use GDI+ to save the picture
1036 Bitmap
bitmap(hbm
, NULL
);
1037 if (bitmap
.GetLastStatus()==Ok
)
1039 // Get the CLSID of the encoder.
1041 if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".png"))==0)
1042 ret
= GetEncoderClsid(L
"image/png", &encoderClsid
);
1043 else if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".jpg"))==0)
1044 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1045 else if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".jpeg"))==0)
1046 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1047 else if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".bmp"))==0)
1048 ret
= GetEncoderClsid(L
"image/bmp", &encoderClsid
);
1049 else if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".gif"))==0)
1050 ret
= GetEncoderClsid(L
"image/gif", &encoderClsid
);
1053 sSavePath
+= _T(".jpg");
1054 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1058 CStringW tfile
= CStringW(sSavePath
);
1059 bitmap
.Save(tfile
, &encoderClsid
, NULL
);
1063 sErrormessage
.Format(IDS_REVGRAPH_ERR_NOENCODER
, (LPCTSTR
)CPathUtils::GetFileExtFromPath(sSavePath
));
1068 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_NOBITMAP
);
1071 dc
.SelectObject(oldbm
);
1074 if (!sErrormessage
.IsEmpty())
1076 ::MessageBox(m_hWnd
, sErrormessage
, _T("TortoiseGit"), MB_ICONERROR
);
1079 catch (CException
* pE
)
1081 TCHAR szErrorMsg
[2048] = { 0 };
1082 pE
->GetErrorMessage(szErrorMsg
, 2048);
1084 ::MessageBox(m_hWnd
, szErrorMsg
, _T("TortoiseGit"), MB_ICONERROR
);
1090 BOOL
CRevisionGraphWnd::OnMouseWheel(UINT nFlags
, short zDelta
, CPoint pt
)
1092 if (IsUpdateJobRunning())
1093 return __super::OnMouseWheel(nFlags
, zDelta
, pt
);
1095 if (GetKeyState(VK_CONTROL
)&0x8000)
1097 float newZoom
= m_fZoomFactor
* (zDelta
< 0 ? ZOOM_STEP
: 1.0f
/ZOOM_STEP
);
1098 DoZoom (max (MIN_ZOOM
, min (MAX_ZOOM
, newZoom
)));
1102 int orientation
= GetKeyState(VK_SHIFT
)&0x8000 ? SB_HORZ
: SB_VERT
;
1103 int pos
= GetScrollPos(orientation
);
1105 SetScrollPos(orientation
, pos
);
1108 return __super::OnMouseWheel(nFlags
, zDelta
, pt
);
1111 void CRevisionGraphWnd::OnMouseHWheel(UINT nFlags
, short zDelta
, CPoint pt
)
1113 if (IsUpdateJobRunning())
1114 return __super::OnMouseHWheel(nFlags
, zDelta
, pt
);
1116 int orientation
= GetKeyState(VK_SHIFT
)&0x8000 ? SB_VERT
: SB_HORZ
;
1117 int pos
= GetScrollPos(orientation
);
1119 SetScrollPos(orientation
, pos
);
1122 return __super::OnMouseHWheel(nFlags
, zDelta
, pt
);
1125 bool CRevisionGraphWnd::UpdateSelectedEntry (node clickedentry
)
1127 if ((m_SelectedEntry1
== NULL
)&&(clickedentry
== NULL
))
1130 if (m_SelectedEntry1
== NULL
)
1132 m_SelectedEntry1
= clickedentry
;
1135 if ((m_SelectedEntry2
== NULL
)&&(clickedentry
!= m_SelectedEntry1
))
1137 m_SelectedEntry1
= clickedentry
;
1140 if (m_SelectedEntry1
&& m_SelectedEntry2
)
1142 if ((m_SelectedEntry2
!= clickedentry
)&&(m_SelectedEntry1
!= clickedentry
))
1145 if (m_SelectedEntry1
== NULL
)
1151 void CRevisionGraphWnd::AppendMenu
1157 // separate different groups / section within the context menu
1159 if (popup
.GetMenuItemCount() > 0)
1161 UINT lastCommand
= popup
.GetMenuItemID (popup
.GetMenuItemCount()-1);
1162 if ((lastCommand
& GROUP_MASK
) != (command
& GROUP_MASK
))
1163 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1166 // actually add the new item
1168 CString titleString
;
1169 titleString
.LoadString (title
);
1170 popup
.AppendMenu (MF_STRING
| flags
, command
, titleString
);
1173 void CRevisionGraphWnd::AppendMenu(CMenu
&popup
, CString title
, UINT command
, CString
*extra
, CMenu
*submenu
)
1175 // separate different groups / section within the context menu
1176 if (popup
.GetMenuItemCount() > 0)
1178 UINT lastCommand
= popup
.GetMenuItemID(popup
.GetMenuItemCount() - 1);
1179 if ((lastCommand
& GROUP_MASK
) != (command
& GROUP_MASK
))
1180 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1183 // actually add the new item
1185 memset(&mii
, 0, sizeof(mii
));
1186 mii
.cbSize
= sizeof(MENUITEMINFO
);
1187 mii
.fMask
= MIIM_STRING
| MIIM_ID
| (extra
? MIIM_DATA
: 0) | (submenu
? MIIM_SUBMENU
: 0);
1189 mii
.hSubMenu
= submenu
? submenu
->m_hMenu
: NULL
;
1190 mii
.dwItemData
= (ULONG_PTR
)extra
;
1191 mii
.dwTypeData
= title
.GetBuffer();
1192 InsertMenuItem(popup
, popup
.GetMenuItemCount(), TRUE
, &mii
);
1193 title
.ReleaseBuffer();
1196 void CRevisionGraphWnd::AddGraphOps (CMenu
& /*popup*/, const CVisibleGraphNode
* /*node*/)
1199 CSyncPointer
<CGraphNodeStates
> nodeStates (m_state
.GetNodeStates());
1203 DWORD state
= nodeStates
->GetCombinedFlags();
1206 if (state
& CGraphNodeStates::COLLAPSED_ALL
)
1207 AppendMenu (popup
, IDS_REVGRAPH_POPUP_EXPAND_ALL
, ID_EXPAND_ALL
);
1209 if (state
& CGraphNodeStates::SPLIT_ALL
)
1210 AppendMenu (popup
, IDS_REVGRAPH_POPUP_JOIN_ALL
, ID_JOIN_ALL
);
1215 DWORD state
= nodeStates
->GetFlags (node
);
1217 if (node
->GetSource() || (state
& CGraphNodeStates::COLLAPSED_ABOVE
))
1219 , (state
& CGraphNodeStates::COLLAPSED_ABOVE
)
1220 ? IDS_REVGRAPH_POPUP_EXPAND_ABOVE
1221 : IDS_REVGRAPH_POPUP_COLLAPSE_ABOVE
1222 , ID_GRAPH_EXPANDCOLLAPSE_ABOVE
);
1224 if (node
->GetFirstCopyTarget() || (state
& CGraphNodeStates::COLLAPSED_RIGHT
))
1226 , (state
& CGraphNodeStates::COLLAPSED_RIGHT
)
1227 ? IDS_REVGRAPH_POPUP_EXPAND_RIGHT
1228 : IDS_REVGRAPH_POPUP_COLLAPSE_RIGHT
1229 , ID_GRAPH_EXPANDCOLLAPSE_RIGHT
);
1231 if (node
->GetNext() || (state
& CGraphNodeStates::COLLAPSED_BELOW
))
1233 , (state
& CGraphNodeStates::COLLAPSED_BELOW
)
1234 ? IDS_REVGRAPH_POPUP_EXPAND_BELOW
1235 : IDS_REVGRAPH_POPUP_COLLAPSE_BELOW
1236 , ID_GRAPH_EXPANDCOLLAPSE_BELOW
);
1238 if (node
->GetSource() || (state
& CGraphNodeStates::SPLIT_ABOVE
))
1240 , (state
& CGraphNodeStates::SPLIT_ABOVE
)
1241 ? IDS_REVGRAPH_POPUP_JOIN_ABOVE
1242 : IDS_REVGRAPH_POPUP_SPLIT_ABOVE
1243 , ID_GRAPH_SPLITJOIN_ABOVE
);
1245 if (node
->GetFirstCopyTarget() || (state
& CGraphNodeStates::SPLIT_RIGHT
))
1247 , (state
& CGraphNodeStates::SPLIT_RIGHT
)
1248 ? IDS_REVGRAPH_POPUP_JOIN_RIGHT
1249 : IDS_REVGRAPH_POPUP_SPLIT_RIGHT
1250 , ID_GRAPH_SPLITJOIN_RIGHT
);
1252 if (node
->GetNext() || (state
& CGraphNodeStates::SPLIT_BELOW
))
1254 , (state
& CGraphNodeStates::SPLIT_BELOW
)
1255 ? IDS_REVGRAPH_POPUP_JOIN_BELOW
1256 : IDS_REVGRAPH_POPUP_SPLIT_BELOW
1257 , ID_GRAPH_SPLITJOIN_BELOW
);
1262 CString
CRevisionGraphWnd::GetSelectedURL() const
1265 if (m_SelectedEntry1
== NULL
)
1268 CString URL
= m_state
.GetRepositoryRoot()
1269 + CUnicodeUtils::GetUnicode (m_SelectedEntry1
->GetPath().GetPath().c_str());
1270 URL
= CUnicodeUtils::GetUnicode(CPathUtils::PathEscape(CUnicodeUtils::GetUTF8(URL
)));
1277 CString
CRevisionGraphWnd::GetWCURL() const
1280 CTGitPath
path (m_sPath
);
1285 const SVNInfoData
* status
1286 = info
.GetFirstFileInfo (path
, SVNRev(), SVNRev());
1288 return status
== NULL
? CString() : status
->url
;
1293 void CRevisionGraphWnd::DoShowLog()
1296 if(m_SelectedEntry1
== NULL
)
1301 if(m_SelectedEntry2
!= NULL
)
1302 sCmd
.Format(_T("/command:log %s /startrev:%s /endrev:%s"),
1303 this->m_sPath
.IsEmpty() ? _T("") : (_T("/path:\"") + this->m_sPath
+ _T("\"")),
1304 this->m_logEntries
[m_SelectedEntry1
->index()].ToString(),
1305 this->m_logEntries
[m_SelectedEntry2
->index()].ToString());
1307 sCmd
.Format(_T("/command:log %s /endrev:%s"),
1308 this->m_sPath
.IsEmpty() ? _T("") : (_T("/path:\"") + this->m_sPath
+ _T("\"")),
1309 this->m_logEntries
[m_SelectedEntry1
->index()].ToString());
1311 CAppUtils::RunTortoiseGitProc(sCmd
);
1315 void CRevisionGraphWnd::DoCheckForModification()
1318 dlg
.m_pathList
= CTGitPathList (CTGitPath (m_sPath
));
1322 void CRevisionGraphWnd::DoMergeTo()
1325 CString URL
= GetSelectedURL();
1326 CString path
= m_sPath
;
1327 CBrowseFolder folderBrowser
;
1328 folderBrowser
.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_MERGETO
)));
1329 if (folderBrowser
.Show(GetSafeHwnd(), path
, path
) == CBrowseFolder::OK
)
1331 CSVNProgressDlg dlg
;
1332 dlg
.SetCommand(CSVNProgressDlg::SVNProgress_Merge
);
1333 dlg
.SetPathList(CTGitPathList(CTGitPath(path
)));
1335 dlg
.SetSecondUrl(URL
);
1336 SVNRevRangeArray revarray
;
1337 revarray
.AddRevRange (m_SelectedEntry1
->GetRevision()-1, svn_revnum_t(m_SelectedEntry1
->GetRevision()));
1338 dlg
.SetRevisionRanges(revarray
);
1344 void CRevisionGraphWnd::DoUpdate()
1347 CSVNProgressDlg progDlg
;
1348 progDlg
.SetCommand (CSVNProgressDlg::SVNProgress_Update
);
1349 progDlg
.SetOptions (0); // don't ignore externals
1350 progDlg
.SetPathList (CTGitPathList (CTGitPath (m_sPath
)));
1351 progDlg
.SetRevision (m_SelectedEntry1
->GetRevision());
1355 if (m_state
.GetFetchedWCState())
1356 m_parent
->UpdateFullHistory();
1360 void CRevisionGraphWnd::DoSwitch(CString rev
)
1362 CAppUtils::PerformSwitch(rev
);
1365 void CRevisionGraphWnd::DoSwitchToHead()
1368 CSVNProgressDlg progDlg
;
1369 progDlg
.SetCommand (CSVNProgressDlg::SVNProgress_Switch
);
1370 progDlg
.SetPathList (CTGitPathList (CTGitPath (m_sPath
)));
1371 progDlg
.SetUrl (GetSelectedURL());
1372 progDlg
.SetRevision (SVNRev::REV_HEAD
);
1373 progDlg
.SetPegRevision (m_SelectedEntry1
->GetRevision());
1376 if (m_state
.GetFetchedWCState())
1377 m_parent
->UpdateFullHistory();
1381 void CRevisionGraphWnd::DoBrowseRepo()
1383 if (m_SelectedEntry1
== NULL
)
1387 sCmd
.Format(_T("/command:repobrowser %s /rev:%s"),
1388 this->m_sPath
.IsEmpty() ? _T("") : (_T("/path:\"") + this->m_sPath
+ _T("\"")),
1389 GetFriendRefName(m_SelectedEntry1
));
1391 CAppUtils::RunTortoiseGitProc(sCmd
);
1394 void CRevisionGraphWnd::ResetNodeFlags (DWORD
/*flags*/)
1396 // m_state.GetNodeStates()->ResetFlags (flags);
1397 // m_parent->StartWorkerThread();
1400 void CRevisionGraphWnd::ToggleNodeFlag (const CVisibleGraphNode
* /*node*/, DWORD
/*flag*/)
1403 CSyncPointer
<CGraphNodeStates
> nodeStates (m_state
.GetNodeStates());
1405 if (nodeStates
->GetFlags (node
) & flag
)
1406 nodeStates
->ResetFlags (node
, flag
);
1408 nodeStates
->SetFlags (node
, flag
);
1410 m_parent
->StartWorkerThread();
1414 void CRevisionGraphWnd::DoCopyRefs()
1416 if (m_SelectedEntry1
== NULL
)
1419 STRING_VECTOR list
= GetFriendRefNames(m_SelectedEntry1
);
1422 text
= m_logEntries
[m_SelectedEntry1
->index()].ToString();
1423 for (size_t i
= 0; i
< list
.size(); ++i
)
1426 text
.Append(_T("\r\n"));
1427 text
.Append(list
[i
]);
1429 CStringUtils::WriteAsciiStringToClipboard(text
, m_hWnd
);
1432 void CRevisionGraphWnd::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
1434 if (IsUpdateJobRunning())
1437 CPoint clientpoint
= point
;
1438 this->ScreenToClient(&clientpoint
);
1440 node nodeIndex
= GetHitNode (clientpoint
);
1442 if ( !UpdateSelectedEntry (nodeIndex
))
1448 if (!popup
.CreatePopupMenu())
1451 bool bothPresent
= (m_SelectedEntry2
&& m_SelectedEntry1
);
1453 AppendMenu (popup
, IDS_REPOBROWSE_SHOWLOG
, ID_SHOWLOG
);
1455 STRING_VECTOR branchNames
;
1456 if (m_SelectedEntry1
&& (m_SelectedEntry2
== nullptr))
1458 AppendMenu(popup
, IDS_LOG_BROWSEREPO
, ID_BROWSEREPO
);
1460 CString currentBranch
= g_Git
.GetCurrentBranch();
1461 CGit::REF_TYPE refType
= CGit::LOCAL_BRANCH
;
1462 STRING_VECTOR allBranchNames
= GetFriendRefNames(m_SelectedEntry1
, &refType
, 1);
1463 for (size_t i
= 0; i
< allBranchNames
.size(); ++i
)
1464 if (allBranchNames
[i
] != currentBranch
)
1465 branchNames
.push_back(allBranchNames
[i
]);
1466 if (branchNames
.size() == 1)
1469 text
.Format(_T("%s \"%s\""), CString(MAKEINTRESOURCE(IDS_SWITCH_BRANCH
)), branchNames
[0]);
1470 AppendMenu(popup
, text
, ID_SWITCH
, &branchNames
[0]);
1472 else if (branchNames
.size() > 1)
1475 switchMenu
.CreatePopupMenu();
1476 for (size_t i
= 0; i
< branchNames
.size(); ++i
)
1477 AppendMenu(switchMenu
, branchNames
[i
], ID_SWITCH
+ ((int)(i
+ 1) << 16), &branchNames
[i
]);
1478 AppendMenu(popup
, CString(MAKEINTRESOURCE(IDS_SWITCH_BRANCH
)), ID_SWITCH
, NULL
, &switchMenu
);
1481 AppendMenu(popup
, IDS_COPY_REF_NAMES
, ID_COPYREFS
);
1483 AppendMenu(popup
, IDS_REVGRAPH_POPUP_COMPAREHEADS
, ID_COMPAREHEADS
);
1484 AppendMenu(popup
, IDS_REVGRAPH_POPUP_UNIDIFFHEADS
, ID_UNIDIFFHEADS
);
1486 AppendMenu(popup
, IDS_LOG_POPUP_COMPARE
, ID_COMPAREWT
);
1491 AppendMenu (popup
, IDS_REVGRAPH_POPUP_COMPAREREVS
, ID_COMPAREREVS
);
1492 AppendMenu (popup
, IDS_REVGRAPH_POPUP_UNIDIFFREVS
, ID_UNIDIFFREVS
);
1495 // AddGraphOps (popup, clickedentry);
1497 // if the context menu is invoked through the keyboard, we have to use
1498 // a calculated position on where to anchor the menu on
1499 if ((point
.x
== -1) && (point
.y
== -1))
1501 CRect rect
= GetWindowRect();
1502 point
= rect
.CenterPoint();
1505 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
| TPM_RIGHTBUTTON
, point
.x
, point
.y
, this, 0);
1506 switch (cmd
& 0xFFFF)
1508 case ID_COMPAREREVS
:
1509 if (m_SelectedEntry1
!= NULL
)
1512 case ID_UNIDIFFREVS
:
1513 if (m_SelectedEntry1
!= NULL
)
1514 UnifiedDiffRevs(false);
1516 case ID_UNIDIFFHEADS
:
1517 if (m_SelectedEntry1
!= NULL
)
1518 UnifiedDiffRevs(true);
1526 memset(&mii
, 0, sizeof(mii
));
1527 mii
.cbSize
= sizeof(mii
);
1528 mii
.fMask
|= MIIM_DATA
;
1529 GetMenuItemInfo(popup
, cmd
, FALSE
, &mii
);
1530 CString
*rev
= (CString
*)mii
.dwItemData
;
1534 m_parent
->UpdateFullHistory();
1544 case ID_COMPAREHEADS
:
1545 if (m_SelectedEntry1
!= NULL
)
1546 CompareRevs(_T("HEAD"));
1549 if (m_SelectedEntry1
!= NULL
)
1550 CompareRevs(CGitHash().ToString());
1554 case ID_COMPAREREVS
:
1555 if (m_SelectedEntry1
!= NULL
)
1558 case ID_UNIDIFFREVS
:
1559 if (m_SelectedEntry1
!= NULL
)
1560 UnifiedDiffRevs(false);
1562 case ID_UNIDIFFHEADS
:
1563 if (m_SelectedEntry1
!= NULL
)
1564 UnifiedDiffRevs(true);
1570 DoCheckForModification();
1578 case ID_SWITCHTOHEAD
:
1582 ResetNodeFlags (CGraphNodeStates::COLLAPSED_ALL
);
1585 ResetNodeFlags (CGraphNodeStates::SPLIT_ALL
);
1587 case ID_GRAPH_EXPANDCOLLAPSE_ABOVE
:
1588 ToggleNodeFlag (clickedentry
, CGraphNodeStates::COLLAPSED_ABOVE
);
1590 case ID_GRAPH_EXPANDCOLLAPSE_RIGHT
:
1591 ToggleNodeFlag (clickedentry
, CGraphNodeStates::COLLAPSED_RIGHT
);
1593 case ID_GRAPH_EXPANDCOLLAPSE_BELOW
:
1594 ToggleNodeFlag (clickedentry
, CGraphNodeStates::COLLAPSED_BELOW
);
1596 case ID_GRAPH_SPLITJOIN_ABOVE
:
1597 ToggleNodeFlag (clickedentry
, CGraphNodeStates::SPLIT_ABOVE
);
1599 case ID_GRAPH_SPLITJOIN_RIGHT
:
1600 ToggleNodeFlag (clickedentry
, CGraphNodeStates::SPLIT_RIGHT
);
1602 case ID_GRAPH_SPLITJOIN_BELOW
:
1603 ToggleNodeFlag (clickedentry
, CGraphNodeStates::SPLIT_BELOW
);
1610 void CRevisionGraphWnd::OnMouseMove(UINT nFlags
, CPoint point
)
1613 if (IsUpdateJobRunning())
1615 return __super::OnMouseMove(nFlags
, point
);
1617 if (!m_bIsCanvasMove
)
1619 if (m_bShowOverview
&& (m_OverviewRect
.PtInRect(point
))&&(nFlags
& MK_LBUTTON
))
1622 CRect viewRect
= GetViewRect();
1623 int x
= (int)((point
.x
-m_OverviewRect
.left
- (m_OverviewPosRect
.Width()/2)) / m_previewZoom
* m_fZoomFactor
);
1624 int y
= (int)((point
.y
- m_OverviewRect
.top
- (m_OverviewPosRect
.Height()/2)) / m_previewZoom
* m_fZoomFactor
);
1627 SetScrollbars(y
, x
);
1629 return __super::OnMouseMove(nFlags
, point
);
1633 // update screen if we hover over a different
1634 // node than during the last redraw
1636 CPoint clientPoint
= point
;
1637 GetCursorPos (&clientPoint
);
1638 ScreenToClient (&clientPoint
);
1641 const CRevisionGraphState::SVisibleGlyph
* hitGlyph
1642 = GetHitGlyph (clientPoint
);
1643 const CFullGraphNode
* glyphNode
1644 = hitGlyph
? hitGlyph
->node
->GetBase() : NULL
;
1646 const CFullGraphNode
* hoverNode
= NULL
;
1647 if (m_hoverIndex
!= NO_INDEX
)
1649 CSyncPointer
<const ILayoutNodeList
> nodeList (m_state
.GetNodes());
1650 if (m_hoverIndex
< nodeList
->GetCount())
1651 hoverNode
= nodeList
->GetNode (m_hoverIndex
).node
->GetBase();
1654 //bool onHoverNodeGlyph = (hoverNode != NULL) && (glyphNode == hoverNode);
1656 && ( (m_hoverIndex
!= GetHitNode (clientPoint
))))
1658 m_showHoverGlyphs
= false;
1660 KillTimer (GLYPH_HOVER_EVENT
);
1661 SetTimer (GLYPH_HOVER_EVENT
, GLYPH_HOVER_DELAY
, NULL
);
1666 return __super::OnMouseMove(nFlags
, point
);
1671 int pos_h
= GetScrollPos(SB_HORZ
);
1672 pos_h
-= point
.x
- m_ptMoveCanvas
.x
;
1673 SetScrollPos(SB_HORZ
, pos_h
);
1675 int pos_v
= GetScrollPos(SB_VERT
);
1676 pos_v
-= point
.y
- m_ptMoveCanvas
.y
;
1677 SetScrollPos(SB_VERT
, pos_v
);
1679 m_ptMoveCanvas
= point
;
1683 __super::OnMouseMove(nFlags
, point
);
1686 BOOL
CRevisionGraphWnd::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
1688 CRect viewRect
= GetViewRect();
1690 LPTSTR cursorID
= IDC_ARROW
;
1691 HINSTANCE resourceHandle
= NULL
;
1693 if ((nHitTest
== HTCLIENT
)&&(pWnd
== this)&&(viewRect
.Width())&&(viewRect
.Height())&&(message
))
1696 if (GetCursorPos(&pt
))
1698 ScreenToClient(&pt
);
1699 if (m_OverviewPosRect
.PtInRect(pt
))
1701 resourceHandle
= AfxGetResourceHandle();
1702 cursorID
= GetKeyState(VK_LBUTTON
) & 0x8000
1703 ? MAKEINTRESOURCE(IDC_PANCURDOWN
)
1704 : MAKEINTRESOURCE(IDC_PANCUR
);
1706 if (m_bIsCanvasMove
)
1707 cursorID
= IDC_HAND
;
1711 HCURSOR hCur
= LoadCursor(resourceHandle
, MAKEINTRESOURCE(cursorID
));
1712 if (GetCursor() != hCur
)
1718 void CRevisionGraphWnd::OnTimer (UINT_PTR nIDEvent
)
1720 if (nIDEvent
== GLYPH_HOVER_EVENT
)
1722 KillTimer (GLYPH_HOVER_EVENT
);
1724 m_showHoverGlyphs
= true;
1729 __super::OnTimer (nIDEvent
);
1733 LRESULT
CRevisionGraphWnd::OnWorkerThreadDone(WPARAM
, LPARAM
)
1735 // handle potential race condition between PostMessage and leaving job:
1736 // the background job may not have exited, yet
1738 if (updateJob
.get())
1739 updateJob
->GetResult();
1746 SCROLLINFO sinfo
= { 0 };
1747 sinfo
.cbSize
= sizeof(SCROLLINFO
);
1748 if (GetScrollInfo(SB_HORZ
, &sinfo
))
1750 sinfo
.nPos
= (int)min(max(sinfo
.nMin
, m_GraphAttr
.x(m_HeadNode
) - m_GraphAttr
.width(m_HeadNode
) / 2), sinfo
.nMax
);
1751 SetScrollInfo(SB_HORZ
, &sinfo
);
1753 if (GetScrollInfo(SB_VERT
, &sinfo
))
1755 sinfo
.nPos
= (int)min(max(sinfo
.nMin
, m_GraphAttr
.y(m_HeadNode
) - m_GraphAttr
.height(m_HeadNode
) / 2), sinfo
.nMax
);
1756 SetScrollInfo(SB_VERT
, &sinfo
);
1762 if (m_parent
&& !m_parent
->GetOutputFile().IsEmpty())
1764 // save the graph to the output file and exit
1765 SaveGraphAs(m_parent
->GetOutputFile());
1771 void CRevisionGraphWnd::SetDlgTitle (bool /*offline*/)
1774 if (m_sTitle
.IsEmpty())
1775 GetParent()->GetWindowText(m_sTitle
);
1779 newTitle
.Format (IDS_REVGRAPH_DLGTITLEOFFLINE
, (LPCTSTR
)m_sTitle
);
1781 newTitle
= m_sTitle
;
1783 CAppUtils::SetWindowTitle(GetParent()->GetSafeHwnd(), m_sPath
, newTitle
);