StatGraph: rename some variable and clean up code
[TortoiseGit.git] / src / TortoiseProc / RevisionGraph / RevisionGraphWnd.h
blob8af586828ee761fc892b1cb1202d2d282c099bfb
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2011 - TortoiseSVN
4 // Copyright (C) 2012-2013 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 //#include "RevisionGraph/RevisionGraphState.h"
22 #pragma warning(push)
23 #pragma warning(disable: 4481) // nonstandard extension used: override specifier 'override'
24 #include "Future.h"
25 #pragma warning(pop)
26 #include "ProgressDlg.h"
27 #include "Colors.h"
28 //#include "SVNDiff.h"
29 #include "AppUtils.h"
30 #include "SVG.h"
31 #include "LogDlgHelper.h"
33 #pragma warning(push)
34 #pragma warning(disable: 4100) // unreferenced formal parameter
35 #include <ogdf/layered/SugiyamaLayout.h>
36 #include <ogdf/layered/OptimalRanking.h>
37 #include <ogdf/layered/MedianHeuristic.h>
38 #include <ogdf/layered/OptimalHierarchyLayout.h>
39 #include <ogdf/layered/FastHierarchyLayout.h>
40 #pragma warning(pop)
42 typedef void CVisibleGraphNode;
43 typedef int index_t;
45 using namespace Gdiplus;
46 using namespace async;
48 enum
50 REVGRAPH_PREVIEW_WIDTH = 100,
51 REVGRAPH_PREVIEW_HEIGHT = 200,
53 // don't draw pre-views with more than that number of nodes
55 REVGRAPH_PREVIEW_MAX_NODES = 10000
58 // don't try to draw nodes smaller than that:
60 #define REVGRAPH_MIN_NODE_HIGHT (0.5f)
62 enum
64 // size of the node marker
66 MARKER_SIZE = 11,
68 // radius of the rounded / slanted box corners of the expand / collapse / split / join square gylphs
70 CORNER_SIZE = 12,
72 // font sizes
74 DEFAULT_ZOOM_FONT = 9, // default font size
75 SMALL_ZOOM_FONT = 11, // rel. larger font size for small zoom factors
76 SMALL_ZOOM_FONT_THRESHOLD = 6, // max. "small zoom" font size after scaling
78 // size of the expand / collapse / split / join square gylphs
80 GLYPH_BITMAP_SIZE = 16,
81 GLYPH_SIZE = 12,
83 // glyph display delay definitions
85 GLYPH_HOVER_EVENT = 10, // timer ID for the glyph display delay
86 GLYPH_HOVER_DELAY = 250, // delay until the glyphs are shown [ms]
89 // zoom control
91 const float MIN_ZOOM = 0.01f;
92 const float MAX_ZOOM = 2.0f;
93 const float DEFAULT_ZOOM = 1.0f;
94 const float ZOOM_STEP = 0.9f;
96 // don't draw shadows below this zoom level
98 const float SHADOW_ZOOM_THRESHOLD = 0.2f;
101 * \ingroup TortoiseProc
102 * node shapes for the revision graph
104 enum NodeShape
106 TSVNRectangle,
107 TSVNRoundRect,
108 TSVNOctangle,
109 TSVNEllipse
112 #define MAXFONTS 4
113 #define MAX_TT_LENGTH 60000
114 #define MAX_TT_LENGTH_DEFAULT 1000
116 // forward declarations
118 class CRevisionGraphDlg;
120 // simplify usage of classes from other namespaces
122 //using async::IJob;
123 //using async::CFuture;
126 * \ingroup TortoiseProc
127 * Window class showing a revision graph.
129 * The analyzation of the log data is done in the child class CRevisionGraph.
130 * Here, we handle the window notifications.
132 class CRevisionGraphWnd : public CWnd //, public CRevisionGraph
134 public:
135 CRevisionGraphWnd(); // standard constructor
136 virtual ~CRevisionGraphWnd();
137 enum
139 IDD = IDD_REVISIONGRAPH,
140 WM_WORKERTHREADDONE = WM_APP +1
144 CString m_sPath;
145 GitRev m_pegRev;
147 CLogCache m_LogCache;
148 CLogDataVector m_logEntries;
149 MAP_HASH_NAME m_HashMap;
150 CString m_CurrentBranch;
151 CGitHash m_HeadHash;
153 BOOL m_bCurrentBranch;
154 CString m_FromRev;
155 CString m_ToRev;
157 void ReloadHashMap()
159 m_HashMap.clear();
160 if (g_Git.GetMapHashToFriendName(m_HashMap))
161 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
162 m_CurrentBranch=g_Git.GetCurrentBranch();
163 if (g_Git.GetHash(m_HeadHash, _T("HEAD")))
164 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
167 std::auto_ptr<CFuture<bool>> updateJob;
168 // CRevisionGraphState m_state;
170 void InitView();
171 void Init(CWnd * pParent, LPRECT rect);
172 void SaveGraphAs(CString sSavePath);
174 bool FetchRevisionData ( const CString& path
175 , GitRev pegRevision
176 , CProgressDlg* progress
177 , ITaskbarList3* pTaskbarList
178 , HWND hWnd);
179 bool AnalyzeRevisionData();
180 bool IsUpdateJobRunning() const;
182 bool GetShowOverview() const;
183 void SetShowOverview (bool value);
185 void GetSelected (const CVisibleGraphNode* node, bool head, CTGitPath& path, GitRev& rev, GitRev& peg);
186 void CompareRevs(bool bHead);
187 void UnifiedDiffRevs(bool bHead);
189 CRect GetGraphRect();
190 CRect GetClientRect();
191 CRect GetWindowRect();
192 CRect GetViewRect();
193 void DoZoom (float nZoomFactor, bool updateScrollbars = true);
194 bool CancelMouseZoom();
196 void SetDlgTitle (bool offline);
198 void BuildPreview();
200 protected:
201 DWORD m_dwTicks;
202 CRect m_OverviewPosRect;
203 CRect m_OverviewRect;
205 bool m_bShowOverview;
207 CRevisionGraphDlg *m_parent;
209 ogdf::node m_SelectedEntry1;
210 ogdf::node m_SelectedEntry2;
211 LOGFONT m_lfBaseFont;
212 CFont * m_apFonts[MAXFONTS];
213 int m_nFontSize;
214 CToolTipCtrl * m_pDlgTip;
215 char m_szTip[MAX_TT_LENGTH+1];
216 wchar_t m_wszTip[MAX_TT_LENGTH+1];
217 CString m_sTitle;
219 float m_fZoomFactor;
220 CColors m_Colors;
221 bool m_bTweakTrunkColors;
222 bool m_bTweakTagsColors;
223 bool m_bIsCanvasMove;
224 CPoint m_ptMoveCanvas;
225 CPoint m_ptRubberEnd;
227 CBitmap m_Preview;
228 int m_previewWidth;
229 int m_previewHeight;
230 float m_previewZoom;
232 // index_t m_hoverIndex; // node the cursor currently hovers over
233 ogdf::node m_hoverIndex;
234 DWORD m_hoverGlyphs; // the glyphs shown for \ref m_hoverIndex
235 mutable ogdf::node m_tooltipIndex; // the node index we fetched the tooltip for
236 bool m_showHoverGlyphs; // if true, show the glyphs we currently hover over
237 // (will be activated only after some delay)
239 CString GetFriendRefName(ogdf::node);
241 ogdf::Graph m_Graph;
242 ogdf::GraphAttributes m_GraphAttr;
243 ogdf::SugiyamaLayout m_SugiyamLayout;
245 CRect m_GraphRect;
247 int GetLeftRightMargin() {return 20;};
248 int GetTopBottomMargin() {return 5;};
249 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
250 afx_msg void OnPaint();
251 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
252 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
253 afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
254 afx_msg void OnSize(UINT nType, int cx, int cy);
255 afx_msg INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
256 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
257 afx_msg BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult);
258 afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
259 afx_msg void OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt);
260 afx_msg void OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/);
261 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
262 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
263 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
264 afx_msg void OnTimer(UINT_PTR nIDEvent);
265 afx_msg void OnCaptureChanged(CWnd *pWnd);
266 afx_msg LRESULT OnWorkerThreadDone(WPARAM, LPARAM);
268 DECLARE_MESSAGE_MAP()
269 private:
271 double m_ArrowCos;
272 double m_ArrowSin;
273 double m_ArrowSize;
275 enum MarkerPosition
277 mpLeft = 0,
278 mpRight = 1,
281 enum GlyphType
283 NoGlyph = -1,
284 ExpandGlyph = 0, // "+"
285 CollapseGlyph = 1, // "-"
286 SplitGlyph = 2, // "x"
287 JoinGlyph = 3, // "o"
290 enum GlyphPosition
292 Above = 0,
293 Right = 4,
294 Below = 8,
297 class GraphicsDevice
299 public:
300 GraphicsDevice()
301 : pDC(NULL)
302 , graphics(NULL)
303 , pSVG(NULL)
306 ~GraphicsDevice() {}
307 public:
308 CDC * pDC;
309 Graphics * graphics;
310 SVG * pSVG;
313 class SVGGrouper
315 public:
316 SVGGrouper(SVG * pSVG)
318 m_pSVG = pSVG;
319 if (m_pSVG)
320 m_pSVG->StartGroup();
322 ~SVGGrouper()
324 if (m_pSVG)
325 m_pSVG->EndGroup();
327 private:
328 SVGGrouper() {}
330 SVG * m_pSVG;
333 bool UpdateSelectedEntry (ogdf::node clickedentry);
334 void AppendMenu (CMenu& popup, UINT title, UINT command, UINT flags = MF_ENABLED);
335 void AddGitOps (CMenu& popup);
336 void AddGraphOps (CMenu& popup, const CVisibleGraphNode * node);
337 CString GetSelectedURL() const;
338 CString GetWCURL() const;
339 void DoShowLog();
340 void DoCheckForModification();
341 void DoMergeTo();
342 void DoUpdate();
343 void DoSwitch();
344 void DoSwitchToHead();
345 void DoBrowseRepo();
346 void ResetNodeFlags (DWORD flags);
347 void ToggleNodeFlag (const CVisibleGraphNode *node, DWORD flag);
348 void DoCopyUrl();
350 void SetScrollbar (int bar, int newPos, int clientMax, int graphMax);
351 void SetScrollbars (int nVert = -1, int nHorz = -1);
352 CFont* GetFont(BOOL bItalic = FALSE, BOOL bBold = FALSE);
354 CSize UsableTooltipRect();
355 CString DisplayableText (const CString& wholeText, const CSize& tooltipSize);
356 CString TooltipText (ogdf::node index);
358 CPoint GetLogCoordinates (CPoint point) const;
359 ogdf::node GetHitNode (CPoint point, CSize border = CSize (0, 0)) const;
360 DWORD GetHoverGlyphs (CPoint point) const;
361 PointF cutPoint(ogdf::node v,double lw,PointF ps, PointF pt);
363 // const CRevisionGraphState::SVisibleGlyph* GetHitGlyph (CPoint point) const;
365 void ClearVisibleGlyphs (const CRect& rect);
367 typedef PointF TCutRectangle[8];
368 void CutawayPoints (const RectF& rect, float cutLen, TCutRectangle& result);
369 enum
371 ROUND_UP = 0x1,
372 ROUND_DOWN = 0x2,
373 ROUND_BOTH = 0x3,
375 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);
376 void DrawOctangle (GraphicsDevice& graphics, const Color& penColor, int penWidth, const Pen* pen, const Color& fillColor, const Brush* brush, const RectF& rect);
377 void DrawShape (GraphicsDevice& graphics, const Color& penColor, int penWidth, const Pen* pen, const Color& fillColor, const Brush* brush, const RectF& rect, NodeShape shape);
378 void DrawShadow(GraphicsDevice& graphics, const RectF& rect,
379 Color shadowColor, NodeShape shape);
380 void DrawNode(GraphicsDevice& graphics, const RectF& rect,
381 Color contour, Color overlayColor,
382 const CVisibleGraphNode *node, 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 DrawNodes (GraphicsDevice& graphics, Image* glyphs, const CRect& logRect, const CSize& offset);
405 void DrawConnections (GraphicsDevice& graphics, const CRect& logRect, const CSize& offset);
406 void DrawTexts (GraphicsDevice& graphics, const CRect& logRect, const CSize& offset);
407 void DrawCurrentNodeGlyphs (GraphicsDevice& graphics, Image* glyphs, const CSize& offset);
408 void DrawGraph(GraphicsDevice& graphics, const CRect& rect, int nVScrollPos, int nHScrollPos, bool bDirectDraw);
410 int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
411 void DrawRubberBand();
412 void SetNodeRect(GraphicsDevice& graphics, ogdf::node *pnode, CGitHash rev, int mode = 0);