Fixed some warnings
[TortoiseGit.git] / src / TortoiseProc / RevisionGraph / RevisionGraphWnd.h
blobe2704be831bd1bd0b89077eab9db9ba28350c651
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2011 - TortoiseSVN
4 // Copyright (C) 2012 - 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 g_Git.GetMapHashToFriendName(m_HashMap);
161 m_CurrentBranch=g_Git.GetCurrentBranch();
162 this->m_HeadHash=g_Git.GetHash(_T("HEAD"));
165 std::auto_ptr<CFuture<bool>> updateJob;
166 // CRevisionGraphState m_state;
168 void InitView();
169 void Init(CWnd * pParent, LPRECT rect);
170 void SaveGraphAs(CString sSavePath);
172 bool FetchRevisionData ( const CString& path
173 , GitRev pegRevision
174 , CProgressDlg* progress
175 , ITaskbarList3* pTaskbarList
176 , HWND hWnd);
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(bool bHead);
185 void UnifiedDiffRevs(bool bHead);
187 CRect GetGraphRect();
188 CRect GetClientRect();
189 CRect GetWindowRect();
190 CRect GetViewRect();
191 void DoZoom (float nZoomFactor, bool updateScrollbars = true);
192 bool CancelMouseZoom();
194 void SetDlgTitle (bool offline);
196 void BuildPreview();
198 protected:
199 DWORD m_dwTicks;
200 CRect m_OverviewPosRect;
201 CRect m_OverviewRect;
203 bool m_bShowOverview;
205 CRevisionGraphDlg *m_parent;
207 ogdf::node m_SelectedEntry1;
208 ogdf::node m_SelectedEntry2;
209 LOGFONT m_lfBaseFont;
210 CFont * m_apFonts[MAXFONTS];
211 int m_nFontSize;
212 CToolTipCtrl * m_pDlgTip;
213 char m_szTip[MAX_TT_LENGTH+1];
214 wchar_t m_wszTip[MAX_TT_LENGTH+1];
215 CString m_sTitle;
217 float m_fZoomFactor;
218 CColors m_Colors;
219 bool m_bTweakTrunkColors;
220 bool m_bTweakTagsColors;
221 bool m_bIsRubberBand;
222 CPoint m_ptRubberStart;
223 CPoint m_ptRubberEnd;
225 CBitmap m_Preview;
226 int m_previewWidth;
227 int m_previewHeight;
228 float m_previewZoom;
230 // index_t m_hoverIndex; // node the cursor currently hovers over
231 ogdf::node m_hoverIndex;
232 DWORD m_hoverGlyphs; // the glyphs shown for \ref m_hoverIndex
233 mutable ogdf::node m_tooltipIndex; // the node index we fetched the tooltip for
234 bool m_showHoverGlyphs; // if true, show the glyphs we currently hover over
235 // (will be activated only after some delay)
237 CString GetFriendRefName(ogdf::node);
239 ogdf::Graph m_Graph;
240 ogdf::GraphAttributes m_GraphAttr;
241 ogdf::SugiyamaLayout m_SugiyamLayout;
243 CRect m_GraphRect;
245 int GetLeftRightMargin() {return 20;};
246 int GetTopBottomMargin() {return 5;};
247 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
248 afx_msg void OnPaint();
249 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
250 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
251 afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
252 afx_msg void OnSize(UINT nType, int cx, int cy);
253 afx_msg INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
254 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
255 afx_msg BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult);
256 afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
257 afx_msg void OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt);
258 afx_msg void OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/);
259 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
260 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
261 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
262 afx_msg void OnTimer(UINT_PTR nIDEvent);
263 afx_msg void OnCaptureChanged(CWnd *pWnd);
264 afx_msg LRESULT OnWorkerThreadDone(WPARAM, LPARAM);
266 DECLARE_MESSAGE_MAP()
267 private:
269 double m_ArrowCos;
270 double m_ArrowSin;
271 double m_ArrowSize;
273 enum MarkerPosition
275 mpLeft = 0,
276 mpRight = 1,
279 enum GlyphType
281 NoGlyph = -1,
282 ExpandGlyph = 0, // "+"
283 CollapseGlyph = 1, // "-"
284 SplitGlyph = 2, // "x"
285 JoinGlyph = 3, // "o"
288 enum GlyphPosition
290 Above = 0,
291 Right = 4,
292 Below = 8,
295 class GraphicsDevice
297 public:
298 GraphicsDevice()
299 : pDC(NULL)
300 , graphics(NULL)
301 , pSVG(NULL)
304 ~GraphicsDevice() {}
305 public:
306 CDC * pDC;
307 Graphics * graphics;
308 SVG * pSVG;
311 class SVGGrouper
313 public:
314 SVGGrouper(SVG * pSVG)
316 m_pSVG = pSVG;
317 if (m_pSVG)
318 m_pSVG->StartGroup();
320 ~SVGGrouper()
322 if (m_pSVG)
323 m_pSVG->EndGroup();
325 private:
326 SVGGrouper() {}
328 SVG * m_pSVG;
331 bool UpdateSelectedEntry (ogdf::node clickedentry);
332 void AppendMenu (CMenu& popup, UINT title, UINT command, UINT flags = MF_ENABLED);
333 void AddGitOps (CMenu& popup);
334 void AddGraphOps (CMenu& popup, const CVisibleGraphNode * node);
335 CString GetSelectedURL() const;
336 CString GetWCURL() const;
337 void DoShowLog();
338 void DoCheckForModification();
339 void DoMergeTo();
340 void DoUpdate();
341 void DoSwitch();
342 void DoSwitchToHead();
343 void DoBrowseRepo();
344 void ResetNodeFlags (DWORD flags);
345 void ToggleNodeFlag (const CVisibleGraphNode *node, DWORD flag);
346 void DoCopyUrl();
348 void SetScrollbar (int bar, int newPos, int clientMax, int graphMax);
349 void SetScrollbars (int nVert = -1, int nHorz = -1);
350 CFont* GetFont(BOOL bItalic = FALSE, BOOL bBold = FALSE);
352 CSize UsableTooltipRect();
353 CString DisplayableText (const CString& wholeText, const CSize& tooltipSize);
354 CString TooltipText (ogdf::node index);
356 CPoint GetLogCoordinates (CPoint point) const;
357 ogdf::node GetHitNode (CPoint point, CSize border = CSize (0, 0)) const;
358 DWORD GetHoverGlyphs (CPoint point) const;
359 PointF cutPoint(ogdf::node v,double lw,PointF ps, PointF pt);
361 // const CRevisionGraphState::SVisibleGlyph* GetHitGlyph (CPoint point) const;
363 void ClearVisibleGlyphs (const CRect& rect);
365 typedef PointF TCutRectangle[8];
366 void CutawayPoints (const RectF& rect, float cutLen, TCutRectangle& result);
367 enum
369 ROUND_UP = 0x1,
370 ROUND_DOWN = 0x2,
371 ROUND_BOTH = 0x3,
373 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);
374 void DrawOctangle (GraphicsDevice& graphics, const Color& penColor, int penWidth, const Pen* pen, const Color& fillColor, const Brush* brush, const RectF& rect);
375 void DrawShape (GraphicsDevice& graphics, const Color& penColor, int penWidth, const Pen* pen, const Color& fillColor, const Brush* brush, const RectF& rect, NodeShape shape);
376 void DrawShadow(GraphicsDevice& graphics, const RectF& rect,
377 Color shadowColor, NodeShape shape);
378 void DrawNode(GraphicsDevice& graphics, const RectF& rect,
379 Color contour, Color overlayColor,
380 const CVisibleGraphNode *node, NodeShape shape);
381 RectF TransformRectToScreen (const CRect& rect, const CSize& offset) const;
382 RectF GetNodeRect (const ogdf::node& v, const CSize& offset) const;
383 // RectF GetBranchCover (const ILayoutNodeList* nodeList, index_t nodeIndex, bool upward, const CSize& offset);
385 void DrawSquare (GraphicsDevice& graphics, const PointF& leftTop,
386 const Color& lightColor, const Color& darkColor, const Color& penColor);
387 void DrawGlyph (GraphicsDevice& graphics, Image* glyphs, const PointF& leftTop,
388 GlyphType glyph, GlyphPosition position);
389 void DrawGlyphs (GraphicsDevice& graphics, Image* glyphs, const CVisibleGraphNode* node, const PointF& center,
390 GlyphType glyph1, GlyphType glyph2, GlyphPosition position, DWORD state1, DWORD state2, bool showAll);
391 void DrawGlyphs (GraphicsDevice& graphics, Image* glyphs, const CVisibleGraphNode* node, const RectF& nodeRect,
392 DWORD state, DWORD allowed, bool upsideDown);
393 void DrawMarker ( GraphicsDevice& graphics, const RectF& noderect
394 , MarkerPosition position, int relPosition, Color &penColor);
395 // void IndicateGlyphDirection ( GraphicsDevice& graphics, const ILayoutNodeList* nodeList
396 // , const ILayoutNodeList::SNode& node, const RectF& nodeRect
397 // , DWORD glyphs, bool upsideDown, const CSize& offset);
399 void DrawStripes (GraphicsDevice& graphics, const CSize& offset);
401 void DrawShadows (GraphicsDevice& graphics, const CRect& logRect, const CSize& offset);
402 void DrawNodes (GraphicsDevice& graphics, Image* glyphs, const CRect& logRect, const CSize& offset);
403 void DrawConnections (GraphicsDevice& graphics, const CRect& logRect, const CSize& offset);
404 void DrawTexts (GraphicsDevice& graphics, const CRect& logRect, const CSize& offset);
405 void DrawCurrentNodeGlyphs (GraphicsDevice& graphics, Image* glyphs, const CSize& offset);
406 void DrawGraph(GraphicsDevice& graphics, const CRect& rect, int nVScrollPos, int nHScrollPos, bool bDirectDraw);
408 int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
409 void DrawRubberBand();
410 void SetNodeRect(GraphicsDevice& graphics, ogdf::node *pnode, CGitHash rev, int mode = 0);