1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2011 - TortoiseSVN
4 // Copyright (C) 2012-2018 - 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 "RevisionGraph/RevisionGraphState.h"
23 #include "ProgressDlg.h"
25 //#include "SVNDiff.h"
28 #include "LogDlgHelper.h"
32 #pragma warning(disable: 4100) // unreferenced formal parameter
33 #include <ogdf/layered/SugiyamaLayout.h>
34 #include <ogdf/layered/OptimalRanking.h>
35 #include <ogdf/layered/MedianHeuristic.h>
36 #include <ogdf/layered/OptimalHierarchyLayout.h>
37 #include <ogdf/layered/FastHierarchyLayout.h>
40 typedef void CVisibleGraphNode
;
43 using namespace Gdiplus
;
44 using namespace async
;
48 REVGRAPH_PREVIEW_WIDTH
= 100,
49 REVGRAPH_PREVIEW_HEIGHT
= 200,
51 // don't draw pre-views with more than that number of nodes
53 REVGRAPH_PREVIEW_MAX_NODES
= 10000
56 // don't try to draw nodes smaller than that:
58 #define REVGRAPH_MIN_NODE_HIGHT (0.5f)
62 // size of the node marker
66 // radius of the rounded / slanted box corners of the expand / collapse / split / join square gylphs
72 DEFAULT_ZOOM_FONT
= 9, // default font size
73 SMALL_ZOOM_FONT
= 11, // rel. larger font size for small zoom factors
74 SMALL_ZOOM_FONT_THRESHOLD
= 6, // max. "small zoom" font size after scaling
76 // size of the expand / collapse / split / join square gylphs
78 GLYPH_BITMAP_SIZE
= 16,
81 // glyph display delay definitions
83 GLYPH_HOVER_EVENT
= 10, // timer ID for the glyph display delay
84 GLYPH_HOVER_DELAY
= 250, // delay until the glyphs are shown [ms]
89 const float MIN_ZOOM
= 0.01f
;
90 const float MAX_ZOOM
= 2.0f
;
91 const float DEFAULT_ZOOM
= 1.0f
;
92 const float ZOOM_STEP
= 0.9f
;
94 // don't draw shadows below this zoom level
96 const float SHADOW_ZOOM_THRESHOLD
= 0.2f
;
99 * \ingroup TortoiseProc
100 * node shapes for the revision graph
111 #define MAX_TT_LENGTH 60000
112 #define MAX_TT_LENGTH_DEFAULT 1000
114 // forward declarations
116 class CRevisionGraphDlg
;
118 // simplify usage of classes from other namespaces
121 //using async::CFuture;
124 * \ingroup TortoiseProc
125 * Window class showing a revision graph.
127 * The analyzation of the log data is done in the child class CRevisionGraph.
128 * Here, we handle the window notifications.
130 class CRevisionGraphWnd
: public CWnd
//, public CRevisionGraph
133 CRevisionGraphWnd(); // standard constructor
134 virtual ~CRevisionGraphWnd();
137 IDD
= IDD_REVISIONGRAPH
,
138 WM_WORKERTHREADDONE
= WM_APP
+1
145 CLogCache m_LogCache
;
146 CLogDataVector m_logEntries
;
147 MAP_HASH_NAME m_HashMap
;
148 CString m_CurrentBranch
;
151 BOOL m_bCurrentBranch
;
152 BOOL m_bLocalBranches
;
159 if (g_Git
.GetMapHashToFriendName(m_HashMap
))
160 MessageBox(g_Git
.GetGitLastErr(L
"Could not get all refs."), L
"TortoiseGit", MB_ICONERROR
);
161 m_CurrentBranch
=g_Git
.GetCurrentBranch();
162 if (g_Git
.GetHash(m_HeadHash
, L
"HEAD"))
163 MessageBox(g_Git
.GetGitLastErr(L
"Could not get HEAD hash."), L
"TortoiseGit", MB_ICONERROR
);
166 std::unique_ptr
<CFuture
<bool>> updateJob
;
167 // CRevisionGraphState m_state;
170 void Init(CWnd
* pParent
, LPRECT rect
);
171 void SaveGraphAs(CString sSavePath
);
173 bool FetchRevisionData ( const CString
& path
174 , CProgressDlg
* progress
175 , ITaskbarList3
* pTaskbarList
177 bool AnalyzeRevisionData();
178 bool IsUpdateJobRunning() const;
180 bool GetShowOverview() const;
181 void SetShowOverview (bool value
);
183 void GetSelected (const CVisibleGraphNode
* node
, bool head
, CTGitPath
& path
, GitRev
& rev
, GitRev
& peg
);
184 void CompareRevs(const CString
& revTo
);
185 void UnifiedDiffRevs(bool bHead
);
187 CRect
GetGraphRect();
188 CRect
GetClientRect();
189 CRect
GetWindowRect();
191 void DoZoom (float nZoomFactor
, bool updateScrollbars
= true);
192 bool CancelMouseZoom();
194 void SetDlgTitle (bool offline
);
199 ULONGLONG m_ullTicks
;
200 CRect m_OverviewPosRect
;
201 CRect m_OverviewRect
;
203 bool m_bShowOverview
;
205 CRevisionGraphDlg
*m_parent
;
207 ogdf::node m_HeadNode
;
208 ogdf::node m_SelectedEntry1
;
209 ogdf::node m_SelectedEntry2
;
210 LOGFONT m_lfBaseFont
;
211 CFont
* m_apFonts
[MAXFONTS
];
213 CToolTipCtrl
* m_pDlgTip
;
214 char m_szTip
[MAX_TT_LENGTH
+1];
215 wchar_t m_wszTip
[MAX_TT_LENGTH
+1];
220 bool m_bTweakTrunkColors
;
221 bool m_bTweakTagsColors
;
222 bool m_bIsCanvasMove
;
223 CPoint m_ptMoveCanvas
;
224 CPoint m_ptRubberEnd
;
231 // index_t m_hoverIndex; // node the cursor currently hovers over
232 ogdf::node m_hoverIndex
;
233 DWORD m_hoverGlyphs
; // the glyphs shown for \ref m_hoverIndex
234 mutable ogdf::node m_tooltipIndex
; // the node index we fetched the tooltip for
235 bool m_showHoverGlyphs
; // if true, show the glyphs we currently hover over
236 // (will be activated only after some delay)
238 CString
GetFriendRefName(ogdf::node
);
239 STRING_VECTOR
GetFriendRefNames(ogdf::node
, const CString
* exclude
= nullptr, CGit::REF_TYPE
* onlyRefType
= nullptr);
242 ogdf::GraphAttributes m_GraphAttr
;
243 ogdf::SugiyamaLayout m_SugiyamLayout
;
247 int GetLeftRightMargin() {return 20;};
248 int GetTopBottomMargin() {return 5;};
249 virtual void DoDataExchange(CDataExchange
* pDX
) override
; // DDX/DDV support
250 afx_msg
void OnPaint();
251 virtual ULONG
GetGestureStatus(CPoint ptTouch
) override
;
252 afx_msg BOOL
OnEraseBkgnd(CDC
* pDC
);
253 afx_msg
void OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
);
254 afx_msg
void OnVScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
);
255 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
256 afx_msg INT_PTR
OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const;
257 afx_msg
void OnLButtonDown(UINT nFlags
, CPoint point
);
258 afx_msg BOOL
OnToolTipNotify(UINT id
, NMHDR
*pNMHDR
, LRESULT
*pResult
);
259 afx_msg BOOL
OnMouseWheel(UINT nFlags
, short zDelta
, CPoint pt
);
260 afx_msg
void OnMouseHWheel(UINT nFlags
, short zDelta
, CPoint pt
);
261 afx_msg
void OnContextMenu(CWnd
* /*pWnd*/, CPoint
/*point*/);
262 afx_msg
void OnMouseMove(UINT nFlags
, CPoint point
);
263 afx_msg
void OnLButtonUp(UINT nFlags
, CPoint point
);
264 afx_msg BOOL
OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
);
265 afx_msg
void OnTimer(UINT_PTR nIDEvent
);
266 afx_msg
void OnCaptureChanged(CWnd
*pWnd
);
267 afx_msg LRESULT
OnWorkerThreadDone(WPARAM
, LPARAM
);
269 DECLARE_MESSAGE_MAP()
285 ExpandGlyph
= 0, // "+"
286 CollapseGlyph
= 1, // "-"
287 SplitGlyph
= 2, // "x"
288 JoinGlyph
= 3, // "o"
313 Graphviz
* pGraphviz
;
319 SVGGrouper(SVG
* pSVG
)
323 m_pSVG
->StartGroup();
336 bool UpdateSelectedEntry (ogdf::node clickedentry
);
337 void AppendMenu (CMenu
& popup
, UINT title
, UINT command
, UINT flags
= MF_ENABLED
);
338 void AppendMenu(CMenu
& popup
, CString title
, UINT command
, CString
* extra
= nullptr, CMenu
* submenu
= nullptr);
339 void AddGraphOps (CMenu
& popup
, const CVisibleGraphNode
* node
);
340 CString
GetSelectedURL() const;
341 CString
GetWCURL() const;
343 void DoCheckForModification();
346 void DoSwitch(CString rev
);
347 void DoSwitchToHead();
349 void ResetNodeFlags (DWORD flags
);
350 void ToggleNodeFlag (const CVisibleGraphNode
*node
, DWORD flag
);
353 void SetScrollbar (int bar
, int newPos
, int clientMax
, int graphMax
);
354 void SetScrollbars (int nVert
= -1, int nHorz
= -1);
355 CFont
* GetFont(BOOL bItalic
= FALSE
, BOOL bBold
= FALSE
);
357 CSize
UsableTooltipRect();
358 CString
DisplayableText (const CString
& wholeText
, const CSize
& tooltipSize
);
359 CString
TooltipText (ogdf::node index
);
361 CPoint
GetLogCoordinates (CPoint point
) const;
362 ogdf::node
GetHitNode (CPoint point
, CSize border
= CSize (0, 0)) const;
363 DWORD
GetHoverGlyphs (CPoint point
) const;
364 PointF
cutPoint(ogdf::node v
,double lw
,PointF ps
, PointF pt
);
366 // const CRevisionGraphState::SVisibleGlyph* GetHitGlyph (CPoint point) const;
368 void ClearVisibleGlyphs (const CRect
& rect
);
370 typedef PointF TCutRectangle
[8];
371 void CutawayPoints (const RectF
& rect
, float cutLen
, TCutRectangle
& result
);
378 void DrawRoundedRect (GraphicsDevice
& graphics
, const Color
& penColor
, int penWidth
, const Pen
* pen
, const Color
& fillColor
, const Brush
* brush
, const RectF
& rect
, int mask
=ROUND_BOTH
);
379 void DrawOctangle (GraphicsDevice
& graphics
, const Color
& penColor
, int penWidth
, const Pen
* pen
, const Color
& fillColor
, const Brush
* brush
, const RectF
& rect
);
380 void DrawShape (GraphicsDevice
& graphics
, const Color
& penColor
, int penWidth
, const Pen
* pen
, const Color
& fillColor
, const Brush
* brush
, const RectF
& rect
, NodeShape shape
);
381 void DrawShadow(GraphicsDevice
& graphics
, const RectF
& rect
,
382 Color shadowColor
, NodeShape shape
);
383 RectF
TransformRectToScreen (const CRect
& rect
, const CSize
& offset
) const;
384 RectF
GetNodeRect (const ogdf::node
& v
, const CSize
& offset
) const;
385 // RectF GetBranchCover (const ILayoutNodeList* nodeList, index_t nodeIndex, bool upward, const CSize& offset);
387 void DrawSquare (GraphicsDevice
& graphics
, const PointF
& leftTop
,
388 const Color
& lightColor
, const Color
& darkColor
, const Color
& penColor
);
389 void DrawGlyph (GraphicsDevice
& graphics
, Image
* glyphs
, const PointF
& leftTop
,
390 GlyphType glyph
, GlyphPosition position
);
391 void DrawGlyphs (GraphicsDevice
& graphics
, Image
* glyphs
, const CVisibleGraphNode
* node
, const PointF
& center
,
392 GlyphType glyph1
, GlyphType glyph2
, GlyphPosition position
, DWORD state1
, DWORD state2
, bool showAll
);
393 void DrawGlyphs (GraphicsDevice
& graphics
, Image
* glyphs
, const CVisibleGraphNode
* node
, const RectF
& nodeRect
,
394 DWORD state
, DWORD allowed
, bool upsideDown
);
395 void DrawMarker ( GraphicsDevice
& graphics
, const RectF
& noderect
396 , MarkerPosition position
, int relPosition
, const Color
& penColor
, int num
);
397 // void IndicateGlyphDirection ( GraphicsDevice& graphics, const ILayoutNodeList* nodeList
398 // , const ILayoutNodeList::SNode& node, const RectF& nodeRect
399 // , DWORD glyphs, bool upsideDown, const CSize& offset);
401 void DrawStripes (GraphicsDevice
& graphics
, const CSize
& offset
);
403 void DrawShadows (GraphicsDevice
& graphics
, const CRect
& logRect
, const CSize
& offset
);
404 void DrawConnections (GraphicsDevice
& graphics
, const CRect
& logRect
, const CSize
& offset
);
405 void DrawTexts (GraphicsDevice
& graphics
, const CRect
& logRect
, const CSize
& offset
);
406 void DrawCurrentNodeGlyphs (GraphicsDevice
& graphics
, Image
* glyphs
, const CSize
& offset
);
407 void DrawGraph(GraphicsDevice
& graphics
, const CRect
& rect
, int nVScrollPos
, int nHScrollPos
, bool bDirectDraw
);
409 int GetEncoderClsid(const WCHAR
* format
, CLSID
* pClsid
);
410 void SetNodeRect(GraphicsDevice
& graphics
, ogdf::node
*pnode
, CGitHash rev
, int mode
= 0);