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)
111 memset(&m_lfBaseFont
, 0, sizeof(LOGFONT
));
112 std::fill_n(m_apFonts
, MAXFONTS
, (CFont
*)NULL
);
115 HINSTANCE hInst
= AfxGetInstanceHandle();
116 #define REVGRAPH_CLASSNAME _T("Revgraph_windowclass")
117 if (!(::GetClassInfo(hInst
, REVGRAPH_CLASSNAME
, &wndcls
)))
119 // otherwise we need to register a new class
120 wndcls
.style
= CS_DBLCLKS
| CS_OWNDC
;
121 wndcls
.lpfnWndProc
= ::DefWindowProc
;
122 wndcls
.cbClsExtra
= wndcls
.cbWndExtra
= 0;
123 wndcls
.hInstance
= hInst
;
125 wndcls
.hCursor
= AfxGetApp()->LoadStandardCursor(IDC_ARROW
);
126 wndcls
.hbrBackground
= (HBRUSH
) (COLOR_WINDOW
+ 1);
127 wndcls
.lpszMenuName
= NULL
;
128 wndcls
.lpszClassName
= REVGRAPH_CLASSNAME
;
130 RegisterClass(&wndcls
);
133 m_bTweakTrunkColors
= CRegDWORD(_T("Software\\TortoiseGit\\RevisionGraph\\TweakTrunkColors"), TRUE
) != FALSE
;
134 m_bTweakTagsColors
= CRegDWORD(_T("Software\\TortoiseGit\\RevisionGraph\\TweakTagsColors"), TRUE
) != FALSE
;
138 m_GraphAttr
.init(this->m_Graph
, ogdf::GraphAttributes::nodeGraphics
| ogdf::GraphAttributes::edgeGraphics
|
139 ogdf:: GraphAttributes::nodeLabel
| ogdf::GraphAttributes::nodeColor
|
140 ogdf::GraphAttributes::edgeColor
| ogdf::GraphAttributes::edgeStyle
|
141 ogdf::GraphAttributes::nodeStyle
| ogdf::GraphAttributes::nodeTemplate
);
143 m_SugiyamLayout
.setRanking(::new ogdf::OptimalRanking());
144 m_SugiyamLayout
.setCrossMin(::new ogdf::MedianHeuristic());
146 double pi
= 3.1415926;
147 m_ArrowCos
= cos(pi
/8);
148 m_ArrowSin
= sin(pi
/8);
149 this->m_ArrowSize
= 8;
151 ogdf::node one
= this->m_Graph
.newNode();
152 ogdf::node two
= this->m_Graph
.newNode();
153 ogdf::node three
= this->m_Graph
.newNode();
154 ogdf::node four
= this->m_Graph
.newNode();
157 m_GraphAttr
.width(one
)=100;
158 m_GraphAttr
.height(one
)=200;
159 m_GraphAttr
.width(two
)=100;
160 m_GraphAttr
.height(two
)=100;
161 m_GraphAttr
.width(three
)=100;
162 m_GraphAttr
.height(three
)=20;
163 m_GraphAttr
.width(four
)=100;
164 m_GraphAttr
.height(four
)=20;
166 m_GraphAttr
.labelNode(one
)="One";
167 m_GraphAttr
.labelNode(two
)="Two";
168 m_GraphAttr
.labelNode(three
)="three";
170 this->m_Graph
.newEdge(one
, two
);
171 this->m_Graph
.newEdge(one
, three
);
172 this->m_Graph
.newEdge(two
, four
);
173 this->m_Graph
.newEdge(three
, four
);
176 FastHierarchyLayout
*pOHL
= ::new FastHierarchyLayout
;
177 //It will auto delte when m_SugiyamLayout destory
179 pOHL
->layerDistance(30.0);
180 pOHL
->nodeDistance(25.0);
182 m_SugiyamLayout
.setLayout(pOHL
);
185 //this->m_OHL.layerDistance(30.0);
186 //this->m_OHL.nodeDistance(25.0);
187 //this->m_OHL.weightBalancing(0.8);
188 m_SugiyamLayout
.setLayout(&m_OHL
);
189 m_SugiyamLayout
.call(m_GraphAttr
);
192 PlanarizationLayout pl
;
194 FastPlanarSubgraph
*ps
= ::new FastPlanarSubgraph
;
196 VariableEmbeddingInserter
*ves
= ::new VariableEmbeddingInserter
;
197 ves
->removeReinsert(EdgeInsertionModule::rrAll
);
201 EmbedderMinDepthMaxFaceLayers
*emb
= ::new EmbedderMinDepthMaxFaceLayers
;
204 OrthoLayout
*ol
=::new OrthoLayout
;
205 ol
->separation(20.0);
208 ol
->preferedDir(OrthoDir::odEast
);
209 pl
.setPlanarLayouter(ol
);
211 pl
.call(m_GraphAttr
);
214 forall_nodes(v
,m_Graph
) {
216 TRACE(_T("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(_T("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
)
244 if (m_apFonts
[i
] != NULL
)
246 m_apFonts
[i
]->DeleteObject();
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 _T("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
;
294 wndcls
.hCursor
= AfxGetApp()->LoadStandardCursor(IDC_ARROW
);
295 wndcls
.hbrBackground
= (HBRUSH
) (COLOR_WINDOW
+ 1);
296 wndcls
.lpszMenuName
= NULL
;
297 wndcls
.lpszClassName
= REVGRAPH_CLASSNAME
;
299 RegisterClass(&wndcls
);
302 if (!IsWindow(m_hWnd
))
303 CreateEx(WS_EX_CLIENTEDGE
, REVGRAPH_CLASSNAME
, _T("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_dwTicks
= GetTickCount();
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() != NULL
413 ? CGraphNodeStates::COLLAPSED_RIGHT
| CGraphNodeStates::SPLIT_RIGHT
416 if (topGlyphArea
.PtInRect (logCoordinates
))
417 result
= base
->GetSource() != NULL
418 ? CGraphNodeStates::COLLAPSED_ABOVE
| CGraphNodeStates::SPLIT_ABOVE
421 if (bottomGlyphArea
.PtInRect (logCoordinates
))
422 result
= base
->GetNext() != NULL
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
)
567 if (IsUpdateJobRunning())
568 return __super::OnLButtonDown(nFlags
, point
);
570 // CSyncPointer<const ILayoutNodeList> nodeList (m_state.GetNodes());
574 bool bControl
= !!(GetKeyState(VK_CONTROL
)&0x8000);
575 bool bOverview
= m_bShowOverview
&& m_OverviewRect
.PtInRect(point
);
579 const CRevisionGraphState::SVisibleGlyph
* hitGlyph
580 = GetHitGlyph (point
);
582 if (hitGlyph
!= NULL
)
584 ToggleNodeFlag (hitGlyph
->node
, hitGlyph
->state
);
585 return __super::OnLButtonDown(nFlags
, point
);
588 node nodeIndex
= GetHitNode (point
);
589 if (nodeIndex
!= NULL
)
593 if (m_SelectedEntry1
== nodeIndex
)
595 if (m_SelectedEntry2
)
597 m_SelectedEntry1
= m_SelectedEntry2
;
598 m_SelectedEntry2
= NULL
;
601 m_SelectedEntry1
= NULL
;
603 else if (m_SelectedEntry2
== nodeIndex
)
604 m_SelectedEntry2
= NULL
;
605 else if (m_SelectedEntry1
)
606 m_SelectedEntry2
= nodeIndex
;
608 m_SelectedEntry1
= nodeIndex
;
612 if (m_SelectedEntry1
== nodeIndex
)
613 m_SelectedEntry1
= NULL
;
615 m_SelectedEntry1
= nodeIndex
;
616 m_SelectedEntry2
= NULL
;
623 if ((!bHit
)&&(!bControl
)&&(!bOverview
))
625 m_SelectedEntry1
= NULL
;
626 m_SelectedEntry2
= NULL
;
627 m_bIsCanvasMove
= true;
629 if (m_bShowOverview
&& m_OverviewRect
.PtInRect(point
))
630 m_bIsCanvasMove
= false;
632 m_ptMoveCanvas
= point
;
634 UINT uEnable
= MF_BYCOMMAND
;
635 if ((m_SelectedEntry1
!= NULL
)&&(m_SelectedEntry2
!= NULL
))
636 uEnable
|= MF_ENABLED
;
638 uEnable
|= MF_GRAYED
;
640 EnableMenuItem(GetParent()->GetMenu()->m_hMenu
, ID_VIEW_COMPAREREVISIONS
, uEnable
);
641 EnableMenuItem(GetParent()->GetMenu()->m_hMenu
, ID_VIEW_UNIFIEDDIFF
, uEnable
);
643 uEnable
= MF_BYCOMMAND
;
644 if ((m_SelectedEntry1
!= NULL
)&&(m_SelectedEntry2
== NULL
))
645 uEnable
|= MF_ENABLED
;
647 uEnable
|= MF_GRAYED
;
649 EnableMenuItem(GetParent()->GetMenu()->m_hMenu
, ID_VIEW_UNIFIEDDIFFOFHEADREVISIONS
, uEnable
);
650 EnableMenuItem(GetParent()->GetMenu()->m_hMenu
, ID_VIEW_COMPAREHEADREVISIONS
, uEnable
);
652 __super::OnLButtonDown(nFlags
, point
);
655 void CRevisionGraphWnd::OnCaptureChanged(CWnd
*pWnd
)
657 __super::OnCaptureChanged(pWnd
);
660 void CRevisionGraphWnd::OnLButtonUp(UINT nFlags
, CPoint point
)
662 if (!m_bIsCanvasMove
)
663 return; // we don't have a rubberband, so no zooming necessary
665 m_bIsCanvasMove
= false;
667 if (IsUpdateJobRunning())
668 return __super::OnLButtonUp(nFlags
, point
);
670 // zooming is finished
671 m_ptRubberEnd
= CPoint(0,0);
672 CRect rect
= GetClientRect();
673 int x
= abs(m_ptMoveCanvas
.x
- point
.x
);
674 int y
= abs(m_ptMoveCanvas
.y
- point
.y
);
676 if ((x
< 20)&&(y
< 20))
678 // too small zoom rectangle
679 // assume zooming by accident
681 __super::OnLButtonUp(nFlags
, point
);
685 float xfact
= float(rect
.Width())/float(x
);
686 float yfact
= float(rect
.Height())/float(y
);
687 float fact
= max(yfact
, xfact
);
689 // find out where to scroll to
690 x
= min(m_ptMoveCanvas
.x
, point
.x
) + GetScrollPos(SB_HORZ
);
691 y
= min(m_ptMoveCanvas
.y
, point
.y
) + GetScrollPos(SB_VERT
);
693 float fZoomfactor
= m_fZoomFactor
*fact
;
694 if (fZoomfactor
> 10 * MAX_ZOOM
)
696 // with such a big zoomfactor, the user
697 // most likely zoomed by accident
699 __super::OnLButtonUp(nFlags
, point
);
702 if (fZoomfactor
> MAX_ZOOM
)
704 fZoomfactor
= MAX_ZOOM
;
705 fact
= fZoomfactor
/m_fZoomFactor
;
708 CRevisionGraphDlg
* pDlg
= (CRevisionGraphDlg
*)GetParent();
711 m_fZoomFactor
= fZoomfactor
;
712 pDlg
->DoZoom (m_fZoomFactor
);
713 SetScrollbars(int(float(y
)*fact
), int(float(x
)*fact
));
715 __super::OnLButtonUp(nFlags
, point
);
718 bool CRevisionGraphWnd::CancelMouseZoom()
720 bool bRet
= m_bIsCanvasMove
;
724 m_bIsCanvasMove
= false;
725 m_ptRubberEnd
= CPoint(0,0);
729 INT_PTR
CRevisionGraphWnd::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
732 if (IsUpdateJobRunning())
735 node nodeIndex
= GetHitNode (point
);
736 if (m_tooltipIndex
!= nodeIndex
)
738 // force tooltip to be updated
740 m_tooltipIndex
= nodeIndex
;
744 if (nodeIndex
== NULL
)
747 // if ((GetHoverGlyphs (point) != 0) || (GetHitGlyph (point) != NULL))
750 pTI
->hwnd
= this->m_hWnd
;
751 CWnd::GetClientRect(&pTI
->rect
);
752 pTI
->uFlags
|= TTF_ALWAYSTIP
| TTF_IDISHWND
;
753 pTI
->uId
= (UINT_PTR
)m_hWnd
;
754 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
759 BOOL
CRevisionGraphWnd::OnToolTipNotify(UINT
/*id*/, NMHDR
*pNMHDR
, LRESULT
*pResult
)
761 if (pNMHDR
->idFrom
!= (UINT_PTR
)m_hWnd
)
765 DWORD ptW
= GetMessagePos();
766 point
.x
= GET_X_LPARAM(ptW
);
767 point
.y
= GET_Y_LPARAM(ptW
);
768 ScreenToClient(&point
);
770 CString strTipText
= TooltipText (GetHitNode (point
));
773 if (strTipText
.IsEmpty())
776 CSize tooltipSize
= UsableTooltipRect();
777 strTipText
= DisplayableText (strTipText
, tooltipSize
);
779 // need to handle both ANSI and UNICODE versions of the message
780 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
782 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
783 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, tooltipSize
.cx
);
784 pTTTA
->lpszText
= m_szTip
;
785 WideCharToMultiByte(CP_ACP
, 0, strTipText
, -1, m_szTip
, strTipText
.GetLength()+1, 0, 0);
789 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
790 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, tooltipSize
.cx
);
791 lstrcpyn(m_wszTip
, strTipText
, strTipText
.GetLength()+1);
792 pTTTW
->lpszText
= m_wszTip
;
795 // show the tooltip for 32 seconds. A higher value than 32767 won't work
796 // even though it's nowhere documented!
797 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETDELAYTIME
, TTDT_AUTOPOP
, 32767);
798 return TRUE
; // message was handled
801 CSize
CRevisionGraphWnd::UsableTooltipRect()
805 int screenWidth
= GetSystemMetrics(SM_CXSCREEN
);
806 int screenHeight
= GetSystemMetrics(SM_CYSCREEN
);
808 // get current mouse position
811 if (GetCursorPos (&cursorPos
) == FALSE
)
813 // we could not determine the mouse position
814 // use screen / 2 minus some safety margin
816 return CSize (screenWidth
/ 2 - 20, screenHeight
/ 2 - 20);
819 // tool tip will display in the biggest sector beside the cursor
820 // deduct some safety margin (for the mouse cursor itself
823 ( max (screenWidth
- cursorPos
.x
- 40, cursorPos
.x
- 24)
824 , max (screenHeight
- cursorPos
.y
- 40, cursorPos
.y
- 24));
826 return biggestSector
;
829 CString
CRevisionGraphWnd::DisplayableText ( const CString
& wholeText
830 , const CSize
& tooltipSize
)
835 // no access to the device context -> truncate hard at 1000 chars
837 return wholeText
.GetLength() >= MAX_TT_LENGTH_DEFAULT
838 ? wholeText
.Left (MAX_TT_LENGTH_DEFAULT
-4) + _T(" ...")
842 // select the tooltip font
844 NONCLIENTMETRICS metrics
;
845 metrics
.cbSize
= sizeof (metrics
);
846 if (!SysInfo::Instance().IsVistaOrLater())
848 metrics
.cbSize
-= sizeof(int); // subtract the size of the iPaddedBorderWidth member which is not available on XP
850 SystemParametersInfo (SPI_GETNONCLIENTMETRICS
, metrics
.cbSize
, &metrics
, 0);
853 font
.CreateFontIndirect(&metrics
.lfStatusFont
);
854 CFont
* pOldFont
= dc
->SelectObject (&font
);
856 // split into lines and fill the tooltip rect
860 int remainingHeight
= tooltipSize
.cy
;
862 while (pos
< wholeText
.GetLength())
864 // extract a whole line
866 int nextPos
= wholeText
.Find ('\n', pos
);
868 nextPos
= wholeText
.GetLength();
870 CString line
= wholeText
.Mid (pos
, nextPos
-pos
+1);
872 // find a way to make it fit
874 CSize size
= dc
->GetTextExtent (line
);
875 while (size
.cx
> tooltipSize
.cx
)
877 line
.Delete (line
.GetLength()-1);
878 int nextPos2
= line
.ReverseFind (' ');
882 line
.Delete (nextPos2
+1, line
.GetLength() - pos
-1);
883 size
= dc
->GetTextExtent (line
);
886 // enough room for the new line?
888 remainingHeight
-= size
.cy
;
889 if (remainingHeight
<= size
.cy
)
898 pos
+= line
.GetLength();
901 // relase temp. resources
903 dc
->SelectObject (pOldFont
);
911 CString
CRevisionGraphWnd::TooltipText(node index
)
916 CGitHash hash
= m_logEntries
[index
->index()];
917 GitRev
*rev
= this->m_LogCache
.GetCacheData(hash
);
918 str
+= rev
->m_CommitHash
.ToString();
920 str
+= rev
->GetAuthorName() +_T(" ") + rev
->GetAuthorEmail();
922 str
+= rev
->GetAuthorDate().Format(_T("%Y-%m-%d %H:%M"));
923 str
+= _T("\n\n")+rev
->GetSubject();
925 str
+= rev
->GetBody();
932 void CRevisionGraphWnd::SaveGraphAs(CString sSavePath
)
935 CString extension
= CPathUtils::GetFileExtFromPath(sSavePath
);
936 if (extension
.CompareNoCase(_T(".wmf"))==0)
938 // save the graph as an enhanced metafile
940 wmfDC
.CreateEnhanced(NULL
, sSavePath
, NULL
, _T("TortoiseGit\0Revision Graph\0\0"));
941 float fZoom
= m_fZoomFactor
;
942 m_fZoomFactor
= DEFAULT_ZOOM
;
943 DoZoom(m_fZoomFactor
);
945 rect
= GetViewRect();
948 DrawGraph(dev
, rect
, 0, 0, true);
949 HENHMETAFILE hemf
= wmfDC
.CloseEnhanced();
950 DeleteEnhMetaFile(hemf
);
951 m_fZoomFactor
= fZoom
;
952 DoZoom(m_fZoomFactor
);
954 else if (extension
.CompareNoCase(_T(".svg"))==0)
956 // save the graph as a scalable vector graphic
958 float fZoom
= m_fZoomFactor
;
959 m_fZoomFactor
= DEFAULT_ZOOM
;
960 DoZoom(m_fZoomFactor
);
962 rect
= GetViewRect();
963 svg
.SetViewSize(rect
.Width(), rect
.Height());
966 DrawGraph(dev
, rect
, 0, 0, true);
968 m_fZoomFactor
= fZoom
;
969 DoZoom(m_fZoomFactor
);
971 else if (extension
.CompareNoCase(_T(".gv")) == 0)
974 float fZoom
= m_fZoomFactor
;
975 m_fZoomFactor
= DEFAULT_ZOOM
;
976 DoZoom(m_fZoomFactor
);
978 rect
= GetViewRect();
980 dev
.pGraphviz
= &graphviz
;
981 DrawGraph(dev
, rect
, 0, 0, true);
982 graphviz
.Save(sSavePath
);
983 m_fZoomFactor
= fZoom
;
984 DoZoom(m_fZoomFactor
);
988 // save the graph as a pixel picture instead of a vector picture
989 // create dc to paint on
992 CString sErrormessage
;
995 if (!dc
.CreateCompatibleDC(&ddc
))
997 CFormatMessageWrapper errorDetails
;
999 MessageBox( errorDetails
, _T("Error"), MB_OK
| MB_ICONINFORMATION
);
1004 rect
= GetGraphRect();
1005 rect
.bottom
= (LONG
)(float(rect
.Height()) * m_fZoomFactor
);
1006 rect
.right
= (LONG
)(float(rect
.Width()) * m_fZoomFactor
);
1010 // Initialize header to 0s.
1011 SecureZeroMemory(&bmi
, sizeof(bmi
));
1012 // Fill out the fields you care about.
1013 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1014 bmi
.bmiHeader
.biWidth
= rect
.Width();
1015 bmi
.bmiHeader
.biHeight
= rect
.Height();
1016 bmi
.bmiHeader
.biPlanes
= 1;
1017 bmi
.bmiHeader
.biBitCount
= 24;
1018 bmi
.bmiHeader
.biCompression
= BI_RGB
;
1020 // Create the surface.
1021 hbm
= CreateDIBSection(ddc
.m_hDC
, &bmi
, DIB_RGB_COLORS
,(void **)&pBits
, NULL
, 0);
1024 CMessageBox::Show(m_hWnd
, IDS_REVGRAPH_ERR_NOMEMORY
, IDS_APPNAME
, MB_ICONERROR
);
1027 HBITMAP oldbm
= (HBITMAP
)dc
.SelectObject(hbm
);
1028 // paint the whole graph
1031 DrawGraph(dev
, rect
, 0, 0, true);
1032 // now use GDI+ to save the picture
1035 Bitmap
bitmap(hbm
, NULL
);
1036 if (bitmap
.GetLastStatus()==Ok
)
1038 // Get the CLSID of the encoder.
1040 if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".png"))==0)
1041 ret
= GetEncoderClsid(L
"image/png", &encoderClsid
);
1042 else if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".jpg"))==0)
1043 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1044 else if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".jpeg"))==0)
1045 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1046 else if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".bmp"))==0)
1047 ret
= GetEncoderClsid(L
"image/bmp", &encoderClsid
);
1048 else if (CPathUtils::GetFileExtFromPath(sSavePath
).CompareNoCase(_T(".gif"))==0)
1049 ret
= GetEncoderClsid(L
"image/gif", &encoderClsid
);
1052 sSavePath
+= _T(".jpg");
1053 ret
= GetEncoderClsid(L
"image/jpeg", &encoderClsid
);
1057 CStringW tfile
= CStringW(sSavePath
);
1058 bitmap
.Save(tfile
, &encoderClsid
, NULL
);
1062 sErrormessage
.Format(IDS_REVGRAPH_ERR_NOENCODER
, (LPCTSTR
)CPathUtils::GetFileExtFromPath(sSavePath
));
1067 sErrormessage
.LoadString(IDS_REVGRAPH_ERR_NOBITMAP
);
1070 dc
.SelectObject(oldbm
);
1073 if (!sErrormessage
.IsEmpty())
1075 ::MessageBox(m_hWnd
, sErrormessage
, _T("TortoiseGit"), MB_ICONERROR
);
1078 catch (CException
* pE
)
1080 TCHAR szErrorMsg
[2048] = { 0 };
1081 pE
->GetErrorMessage(szErrorMsg
, 2048);
1083 ::MessageBox(m_hWnd
, szErrorMsg
, _T("TortoiseGit"), MB_ICONERROR
);
1089 BOOL
CRevisionGraphWnd::OnMouseWheel(UINT nFlags
, short zDelta
, CPoint pt
)
1091 if (IsUpdateJobRunning())
1092 return __super::OnMouseWheel(nFlags
, zDelta
, pt
);
1094 if (GetKeyState(VK_CONTROL
)&0x8000)
1096 float newZoom
= m_fZoomFactor
* (zDelta
< 0 ? ZOOM_STEP
: 1.0f
/ZOOM_STEP
);
1097 DoZoom (max (MIN_ZOOM
, min (MAX_ZOOM
, newZoom
)));
1101 int orientation
= GetKeyState(VK_SHIFT
)&0x8000 ? SB_HORZ
: SB_VERT
;
1102 int pos
= GetScrollPos(orientation
);
1104 SetScrollPos(orientation
, pos
);
1107 return __super::OnMouseWheel(nFlags
, zDelta
, pt
);
1110 void CRevisionGraphWnd::OnMouseHWheel(UINT nFlags
, short zDelta
, CPoint pt
)
1112 if (IsUpdateJobRunning())
1113 return __super::OnMouseHWheel(nFlags
, zDelta
, pt
);
1115 int orientation
= GetKeyState(VK_SHIFT
)&0x8000 ? SB_VERT
: SB_HORZ
;
1116 int pos
= GetScrollPos(orientation
);
1118 SetScrollPos(orientation
, pos
);
1121 return __super::OnMouseHWheel(nFlags
, zDelta
, pt
);
1124 bool CRevisionGraphWnd::UpdateSelectedEntry (node clickedentry
)
1126 if ((m_SelectedEntry1
== NULL
)&&(clickedentry
== NULL
))
1129 if (m_SelectedEntry1
== NULL
)
1131 m_SelectedEntry1
= clickedentry
;
1134 if ((m_SelectedEntry2
== NULL
)&&(clickedentry
!= m_SelectedEntry1
))
1136 m_SelectedEntry1
= clickedentry
;
1139 if (m_SelectedEntry1
&& m_SelectedEntry2
)
1141 if ((m_SelectedEntry2
!= clickedentry
)&&(m_SelectedEntry1
!= clickedentry
))
1144 if (m_SelectedEntry1
== NULL
)
1150 void CRevisionGraphWnd::AppendMenu
1156 // 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
1167 CString titleString
;
1168 titleString
.LoadString (title
);
1169 popup
.AppendMenu (MF_STRING
| flags
, command
, titleString
);
1172 void CRevisionGraphWnd::AppendMenu(CMenu
&popup
, CString title
, UINT command
, CString
*extra
, CMenu
*submenu
)
1174 // separate different groups / section within the context menu
1175 if (popup
.GetMenuItemCount() > 0)
1177 UINT lastCommand
= popup
.GetMenuItemID(popup
.GetMenuItemCount() - 1);
1178 if ((lastCommand
& GROUP_MASK
) != (command
& GROUP_MASK
))
1179 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1182 // actually add the new item
1184 memset(&mii
, 0, sizeof(mii
));
1185 mii
.cbSize
= sizeof(MENUITEMINFO
);
1186 mii
.fMask
= MIIM_STRING
| MIIM_ID
| (extra
? MIIM_DATA
: 0) | (submenu
? MIIM_SUBMENU
: 0);
1188 mii
.hSubMenu
= submenu
? submenu
->m_hMenu
: NULL
;
1189 mii
.dwItemData
= (ULONG_PTR
)extra
;
1190 mii
.dwTypeData
= title
.GetBuffer();
1191 InsertMenuItem(popup
, popup
.GetMenuItemCount(), TRUE
, &mii
);
1192 title
.ReleaseBuffer();
1195 void CRevisionGraphWnd::AddGraphOps (CMenu
& /*popup*/, const CVisibleGraphNode
* /*node*/)
1198 CSyncPointer
<CGraphNodeStates
> nodeStates (m_state
.GetNodeStates());
1202 DWORD state
= nodeStates
->GetCombinedFlags();
1205 if (state
& CGraphNodeStates::COLLAPSED_ALL
)
1206 AppendMenu (popup
, IDS_REVGRAPH_POPUP_EXPAND_ALL
, ID_EXPAND_ALL
);
1208 if (state
& CGraphNodeStates::SPLIT_ALL
)
1209 AppendMenu (popup
, IDS_REVGRAPH_POPUP_JOIN_ALL
, ID_JOIN_ALL
);
1214 DWORD state
= nodeStates
->GetFlags (node
);
1216 if (node
->GetSource() || (state
& CGraphNodeStates::COLLAPSED_ABOVE
))
1218 , (state
& CGraphNodeStates::COLLAPSED_ABOVE
)
1219 ? IDS_REVGRAPH_POPUP_EXPAND_ABOVE
1220 : IDS_REVGRAPH_POPUP_COLLAPSE_ABOVE
1221 , ID_GRAPH_EXPANDCOLLAPSE_ABOVE
);
1223 if (node
->GetFirstCopyTarget() || (state
& CGraphNodeStates::COLLAPSED_RIGHT
))
1225 , (state
& CGraphNodeStates::COLLAPSED_RIGHT
)
1226 ? IDS_REVGRAPH_POPUP_EXPAND_RIGHT
1227 : IDS_REVGRAPH_POPUP_COLLAPSE_RIGHT
1228 , ID_GRAPH_EXPANDCOLLAPSE_RIGHT
);
1230 if (node
->GetNext() || (state
& CGraphNodeStates::COLLAPSED_BELOW
))
1232 , (state
& CGraphNodeStates::COLLAPSED_BELOW
)
1233 ? IDS_REVGRAPH_POPUP_EXPAND_BELOW
1234 : IDS_REVGRAPH_POPUP_COLLAPSE_BELOW
1235 , ID_GRAPH_EXPANDCOLLAPSE_BELOW
);
1237 if (node
->GetSource() || (state
& CGraphNodeStates::SPLIT_ABOVE
))
1239 , (state
& CGraphNodeStates::SPLIT_ABOVE
)
1240 ? IDS_REVGRAPH_POPUP_JOIN_ABOVE
1241 : IDS_REVGRAPH_POPUP_SPLIT_ABOVE
1242 , ID_GRAPH_SPLITJOIN_ABOVE
);
1244 if (node
->GetFirstCopyTarget() || (state
& CGraphNodeStates::SPLIT_RIGHT
))
1246 , (state
& CGraphNodeStates::SPLIT_RIGHT
)
1247 ? IDS_REVGRAPH_POPUP_JOIN_RIGHT
1248 : IDS_REVGRAPH_POPUP_SPLIT_RIGHT
1249 , ID_GRAPH_SPLITJOIN_RIGHT
);
1251 if (node
->GetNext() || (state
& CGraphNodeStates::SPLIT_BELOW
))
1253 , (state
& CGraphNodeStates::SPLIT_BELOW
)
1254 ? IDS_REVGRAPH_POPUP_JOIN_BELOW
1255 : IDS_REVGRAPH_POPUP_SPLIT_BELOW
1256 , ID_GRAPH_SPLITJOIN_BELOW
);
1261 CString
CRevisionGraphWnd::GetSelectedURL() const
1264 if (m_SelectedEntry1
== NULL
)
1267 CString URL
= m_state
.GetRepositoryRoot()
1268 + CUnicodeUtils::GetUnicode (m_SelectedEntry1
->GetPath().GetPath().c_str());
1269 URL
= CUnicodeUtils::GetUnicode(CPathUtils::PathEscape(CUnicodeUtils::GetUTF8(URL
)));
1276 CString
CRevisionGraphWnd::GetWCURL() const
1279 CTGitPath
path (m_sPath
);
1284 const SVNInfoData
* status
1285 = info
.GetFirstFileInfo (path
, SVNRev(), SVNRev());
1287 return status
== NULL
? CString() : status
->url
;
1292 void CRevisionGraphWnd::DoShowLog()
1295 if(m_SelectedEntry1
== NULL
)
1300 if(m_SelectedEntry2
!= NULL
)
1301 sCmd
.Format(_T("/command:log %s /startrev:%s /endrev:%s"),
1302 this->m_sPath
.IsEmpty() ? _T("") : (_T("/path:\"") + this->m_sPath
+ _T("\"")),
1303 this->m_logEntries
[m_SelectedEntry1
->index()].ToString(),
1304 this->m_logEntries
[m_SelectedEntry2
->index()].ToString());
1306 sCmd
.Format(_T("/command:log %s /endrev:%s"),
1307 this->m_sPath
.IsEmpty() ? _T("") : (_T("/path:\"") + this->m_sPath
+ _T("\"")),
1308 this->m_logEntries
[m_SelectedEntry1
->index()].ToString());
1310 CAppUtils::RunTortoiseGitProc(sCmd
);
1314 void CRevisionGraphWnd::DoCheckForModification()
1317 dlg
.m_pathList
= CTGitPathList (CTGitPath (m_sPath
));
1321 void CRevisionGraphWnd::DoMergeTo()
1324 CString URL
= GetSelectedURL();
1325 CString path
= m_sPath
;
1326 CBrowseFolder folderBrowser
;
1327 folderBrowser
.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_MERGETO
)));
1328 if (folderBrowser
.Show(GetSafeHwnd(), path
, path
) == CBrowseFolder::OK
)
1330 CSVNProgressDlg dlg
;
1331 dlg
.SetCommand(CSVNProgressDlg::SVNProgress_Merge
);
1332 dlg
.SetPathList(CTGitPathList(CTGitPath(path
)));
1334 dlg
.SetSecondUrl(URL
);
1335 SVNRevRangeArray revarray
;
1336 revarray
.AddRevRange (m_SelectedEntry1
->GetRevision()-1, svn_revnum_t(m_SelectedEntry1
->GetRevision()));
1337 dlg
.SetRevisionRanges(revarray
);
1343 void CRevisionGraphWnd::DoUpdate()
1346 CSVNProgressDlg progDlg
;
1347 progDlg
.SetCommand (CSVNProgressDlg::SVNProgress_Update
);
1348 progDlg
.SetOptions (0); // don't ignore externals
1349 progDlg
.SetPathList (CTGitPathList (CTGitPath (m_sPath
)));
1350 progDlg
.SetRevision (m_SelectedEntry1
->GetRevision());
1354 if (m_state
.GetFetchedWCState())
1355 m_parent
->UpdateFullHistory();
1359 void CRevisionGraphWnd::DoSwitch(CString rev
)
1361 CAppUtils::PerformSwitch(rev
);
1364 void CRevisionGraphWnd::DoSwitchToHead()
1367 CSVNProgressDlg progDlg
;
1368 progDlg
.SetCommand (CSVNProgressDlg::SVNProgress_Switch
);
1369 progDlg
.SetPathList (CTGitPathList (CTGitPath (m_sPath
)));
1370 progDlg
.SetUrl (GetSelectedURL());
1371 progDlg
.SetRevision (SVNRev::REV_HEAD
);
1372 progDlg
.SetPegRevision (m_SelectedEntry1
->GetRevision());
1375 if (m_state
.GetFetchedWCState())
1376 m_parent
->UpdateFullHistory();
1380 void CRevisionGraphWnd::DoBrowseRepo()
1382 if (m_SelectedEntry1
== NULL
)
1386 sCmd
.Format(_T("/command:repobrowser %s /rev:%s"),
1387 this->m_sPath
.IsEmpty() ? _T("") : (_T("/path:\"") + this->m_sPath
+ _T("\"")),
1388 GetFriendRefName(m_SelectedEntry1
));
1390 CAppUtils::RunTortoiseGitProc(sCmd
);
1393 void CRevisionGraphWnd::ResetNodeFlags (DWORD
/*flags*/)
1395 // m_state.GetNodeStates()->ResetFlags (flags);
1396 // m_parent->StartWorkerThread();
1399 void CRevisionGraphWnd::ToggleNodeFlag (const CVisibleGraphNode
* /*node*/, DWORD
/*flag*/)
1402 CSyncPointer
<CGraphNodeStates
> nodeStates (m_state
.GetNodeStates());
1404 if (nodeStates
->GetFlags (node
) & flag
)
1405 nodeStates
->ResetFlags (node
, flag
);
1407 nodeStates
->SetFlags (node
, flag
);
1409 m_parent
->StartWorkerThread();
1413 void CRevisionGraphWnd::DoCopyRefs()
1415 if (m_SelectedEntry1
== NULL
)
1418 STRING_VECTOR list
= GetFriendRefNames(m_SelectedEntry1
);
1421 text
= m_logEntries
[m_SelectedEntry1
->index()].ToString();
1422 for (size_t i
= 0; i
< list
.size(); ++i
)
1425 text
.Append(_T("\r\n"));
1426 text
.Append(list
[i
]);
1428 CStringUtils::WriteAsciiStringToClipboard(text
, m_hWnd
);
1431 void CRevisionGraphWnd::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
1433 if (IsUpdateJobRunning())
1436 CPoint clientpoint
= point
;
1437 this->ScreenToClient(&clientpoint
);
1439 node nodeIndex
= GetHitNode (clientpoint
);
1441 if ( !UpdateSelectedEntry (nodeIndex
))
1447 if (!popup
.CreatePopupMenu())
1450 bool bothPresent
= (m_SelectedEntry2
&& m_SelectedEntry1
);
1452 AppendMenu (popup
, IDS_REPOBROWSE_SHOWLOG
, ID_SHOWLOG
);
1454 STRING_VECTOR branchNames
;
1455 if (m_SelectedEntry1
&& (m_SelectedEntry2
== nullptr))
1457 AppendMenu(popup
, IDS_LOG_BROWSEREPO
, ID_BROWSEREPO
);
1459 CString currentBranch
= g_Git
.GetCurrentBranch();
1460 CGit::REF_TYPE refType
= CGit::LOCAL_BRANCH
;
1461 STRING_VECTOR allBranchNames
= GetFriendRefNames(m_SelectedEntry1
, &refType
, 1);
1462 for (size_t i
= 0; i
< allBranchNames
.size(); ++i
)
1463 if (allBranchNames
[i
] != currentBranch
)
1464 branchNames
.push_back(allBranchNames
[i
]);
1465 if (branchNames
.size() == 1)
1468 text
.Format(_T("%s \"%s\""), CString(MAKEINTRESOURCE(IDS_SWITCH_BRANCH
)), branchNames
[0]);
1469 AppendMenu(popup
, text
, ID_SWITCH
, &branchNames
[0]);
1471 else if (branchNames
.size() > 1)
1474 switchMenu
.CreatePopupMenu();
1475 for (size_t i
= 0; i
< branchNames
.size(); ++i
)
1476 AppendMenu(switchMenu
, branchNames
[i
], ID_SWITCH
+ ((int)(i
+ 1) << 16), &branchNames
[i
]);
1477 AppendMenu(popup
, CString(MAKEINTRESOURCE(IDS_SWITCH_BRANCH
)), ID_SWITCH
, NULL
, &switchMenu
);
1480 AppendMenu(popup
, IDS_COPY_REF_NAMES
, ID_COPYREFS
);
1482 AppendMenu(popup
, IDS_REVGRAPH_POPUP_COMPAREHEADS
, ID_COMPAREHEADS
);
1483 AppendMenu(popup
, IDS_REVGRAPH_POPUP_UNIDIFFHEADS
, ID_UNIDIFFHEADS
);
1485 AppendMenu(popup
, IDS_LOG_POPUP_COMPARE
, ID_COMPAREWT
);
1490 AppendMenu (popup
, IDS_REVGRAPH_POPUP_COMPAREREVS
, ID_COMPAREREVS
);
1491 AppendMenu (popup
, IDS_REVGRAPH_POPUP_UNIDIFFREVS
, ID_UNIDIFFREVS
);
1494 // AddGraphOps (popup, clickedentry);
1496 // if the context menu is invoked through the keyboard, we have to use
1497 // a calculated position on where to anchor the menu on
1498 if ((point
.x
== -1) && (point
.y
== -1))
1500 CRect rect
= GetWindowRect();
1501 point
= rect
.CenterPoint();
1504 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
| TPM_RIGHTBUTTON
, point
.x
, point
.y
, this, 0);
1505 switch (cmd
& 0xFFFF)
1507 case ID_COMPAREREVS
:
1508 if (m_SelectedEntry1
!= NULL
)
1511 case ID_UNIDIFFREVS
:
1512 if (m_SelectedEntry1
!= NULL
)
1513 UnifiedDiffRevs(false);
1515 case ID_UNIDIFFHEADS
:
1516 if (m_SelectedEntry1
!= NULL
)
1517 UnifiedDiffRevs(true);
1525 memset(&mii
, 0, sizeof(mii
));
1526 mii
.cbSize
= sizeof(mii
);
1527 mii
.fMask
|= MIIM_DATA
;
1528 GetMenuItemInfo(popup
, cmd
, FALSE
, &mii
);
1529 CString
*rev
= (CString
*)mii
.dwItemData
;
1533 m_parent
->UpdateFullHistory();
1543 case ID_COMPAREHEADS
:
1544 if (m_SelectedEntry1
!= NULL
)
1545 CompareRevs(_T("HEAD"));
1548 if (m_SelectedEntry1
!= NULL
)
1549 CompareRevs(CGitHash().ToString());
1553 case ID_COMPAREREVS
:
1554 if (m_SelectedEntry1
!= NULL
)
1557 case ID_UNIDIFFREVS
:
1558 if (m_SelectedEntry1
!= NULL
)
1559 UnifiedDiffRevs(false);
1561 case ID_UNIDIFFHEADS
:
1562 if (m_SelectedEntry1
!= NULL
)
1563 UnifiedDiffRevs(true);
1569 DoCheckForModification();
1577 case ID_SWITCHTOHEAD
:
1581 ResetNodeFlags (CGraphNodeStates::COLLAPSED_ALL
);
1584 ResetNodeFlags (CGraphNodeStates::SPLIT_ALL
);
1586 case ID_GRAPH_EXPANDCOLLAPSE_ABOVE
:
1587 ToggleNodeFlag (clickedentry
, CGraphNodeStates::COLLAPSED_ABOVE
);
1589 case ID_GRAPH_EXPANDCOLLAPSE_RIGHT
:
1590 ToggleNodeFlag (clickedentry
, CGraphNodeStates::COLLAPSED_RIGHT
);
1592 case ID_GRAPH_EXPANDCOLLAPSE_BELOW
:
1593 ToggleNodeFlag (clickedentry
, CGraphNodeStates::COLLAPSED_BELOW
);
1595 case ID_GRAPH_SPLITJOIN_ABOVE
:
1596 ToggleNodeFlag (clickedentry
, CGraphNodeStates::SPLIT_ABOVE
);
1598 case ID_GRAPH_SPLITJOIN_RIGHT
:
1599 ToggleNodeFlag (clickedentry
, CGraphNodeStates::SPLIT_RIGHT
);
1601 case ID_GRAPH_SPLITJOIN_BELOW
:
1602 ToggleNodeFlag (clickedentry
, CGraphNodeStates::SPLIT_BELOW
);
1609 void CRevisionGraphWnd::OnMouseMove(UINT nFlags
, CPoint point
)
1612 if (IsUpdateJobRunning())
1614 return __super::OnMouseMove(nFlags
, point
);
1616 if (!m_bIsCanvasMove
)
1618 if (m_bShowOverview
&& (m_OverviewRect
.PtInRect(point
))&&(nFlags
& MK_LBUTTON
))
1621 CRect viewRect
= GetViewRect();
1622 int x
= (int)((point
.x
-m_OverviewRect
.left
- (m_OverviewPosRect
.Width()/2)) / m_previewZoom
* m_fZoomFactor
);
1623 int y
= (int)((point
.y
- m_OverviewRect
.top
- (m_OverviewPosRect
.Height()/2)) / m_previewZoom
* m_fZoomFactor
);
1626 SetScrollbars(y
, x
);
1628 return __super::OnMouseMove(nFlags
, point
);
1632 // update screen if we hover over a different
1633 // node than during the last redraw
1635 CPoint clientPoint
= point
;
1636 GetCursorPos (&clientPoint
);
1637 ScreenToClient (&clientPoint
);
1640 const CRevisionGraphState::SVisibleGlyph
* hitGlyph
1641 = GetHitGlyph (clientPoint
);
1642 const CFullGraphNode
* glyphNode
1643 = hitGlyph
? hitGlyph
->node
->GetBase() : NULL
;
1645 const CFullGraphNode
* hoverNode
= NULL
;
1646 if (m_hoverIndex
!= NO_INDEX
)
1648 CSyncPointer
<const ILayoutNodeList
> nodeList (m_state
.GetNodes());
1649 if (m_hoverIndex
< nodeList
->GetCount())
1650 hoverNode
= nodeList
->GetNode (m_hoverIndex
).node
->GetBase();
1653 //bool onHoverNodeGlyph = (hoverNode != NULL) && (glyphNode == hoverNode);
1655 && ( (m_hoverIndex
!= GetHitNode (clientPoint
))))
1657 m_showHoverGlyphs
= false;
1659 KillTimer (GLYPH_HOVER_EVENT
);
1660 SetTimer (GLYPH_HOVER_EVENT
, GLYPH_HOVER_DELAY
, NULL
);
1665 return __super::OnMouseMove(nFlags
, point
);
1670 int pos_h
= GetScrollPos(SB_HORZ
);
1671 pos_h
-= point
.x
- m_ptMoveCanvas
.x
;
1672 SetScrollPos(SB_HORZ
, pos_h
);
1674 int pos_v
= GetScrollPos(SB_VERT
);
1675 pos_v
-= point
.y
- m_ptMoveCanvas
.y
;
1676 SetScrollPos(SB_VERT
, pos_v
);
1678 m_ptMoveCanvas
= point
;
1682 __super::OnMouseMove(nFlags
, point
);
1685 BOOL
CRevisionGraphWnd::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
1687 CRect viewRect
= GetViewRect();
1689 LPTSTR cursorID
= IDC_ARROW
;
1690 HINSTANCE resourceHandle
= NULL
;
1692 if ((nHitTest
== HTCLIENT
)&&(pWnd
== this)&&(viewRect
.Width())&&(viewRect
.Height())&&(message
))
1695 if (GetCursorPos(&pt
))
1697 ScreenToClient(&pt
);
1698 if (m_OverviewPosRect
.PtInRect(pt
))
1700 resourceHandle
= AfxGetResourceHandle();
1701 cursorID
= GetKeyState(VK_LBUTTON
) & 0x8000
1702 ? MAKEINTRESOURCE(IDC_PANCURDOWN
)
1703 : MAKEINTRESOURCE(IDC_PANCUR
);
1705 if (m_bIsCanvasMove
)
1706 cursorID
= IDC_HAND
;
1710 HCURSOR hCur
= LoadCursor(resourceHandle
, MAKEINTRESOURCE(cursorID
));
1711 if (GetCursor() != hCur
)
1717 void CRevisionGraphWnd::OnTimer (UINT_PTR nIDEvent
)
1719 if (nIDEvent
== GLYPH_HOVER_EVENT
)
1721 KillTimer (GLYPH_HOVER_EVENT
);
1723 m_showHoverGlyphs
= true;
1728 __super::OnTimer (nIDEvent
);
1732 LRESULT
CRevisionGraphWnd::OnWorkerThreadDone(WPARAM
, LPARAM
)
1734 // handle potential race condition between PostMessage and leaving job:
1735 // the background job may not have exited, yet
1737 if (updateJob
.get())
1738 updateJob
->GetResult();
1745 SCROLLINFO sinfo
= { 0 };
1746 sinfo
.cbSize
= sizeof(SCROLLINFO
);
1747 if (GetScrollInfo(SB_HORZ
, &sinfo
))
1749 sinfo
.nPos
= (int)min(max(sinfo
.nMin
, m_GraphAttr
.x(m_HeadNode
) - m_GraphAttr
.width(m_HeadNode
) / 2), sinfo
.nMax
);
1750 SetScrollInfo(SB_HORZ
, &sinfo
);
1752 if (GetScrollInfo(SB_VERT
, &sinfo
))
1754 sinfo
.nPos
= (int)min(max(sinfo
.nMin
, m_GraphAttr
.y(m_HeadNode
) - m_GraphAttr
.height(m_HeadNode
) / 2), sinfo
.nMax
);
1755 SetScrollInfo(SB_VERT
, &sinfo
);
1761 if (m_parent
&& !m_parent
->GetOutputFile().IsEmpty())
1763 // save the graph to the output file and exit
1764 SaveGraphAs(m_parent
->GetOutputFile());
1770 void CRevisionGraphWnd::SetDlgTitle (bool /*offline*/)
1773 if (m_sTitle
.IsEmpty())
1774 GetParent()->GetWindowText(m_sTitle
);
1778 newTitle
.Format (IDS_REVGRAPH_DLGTITLEOFFLINE
, (LPCTSTR
)m_sTitle
);
1780 newTitle
= m_sTitle
;
1782 CAppUtils::SetWindowTitle(GetParent()->GetSafeHwnd(), m_sPath
, newTitle
);