OSDN Git Service

Add Window/Split menu item
[winmerge-jp/winmerge-jp.git] / Src / LocationView.h
1 /** 
2  * @file  LocationView.h
3  *
4  * @brief Declaration of CLocationView class
5  */
6 #pragma once
7
8 #include <vector>
9 #include <memory>
10
11 class CMergeDoc;
12 class CMergeEditView;
13
14 /**
15  * @brief Status for display moved block
16  */
17 enum DISPLAY_MOVED_BLOCKS
18 {
19         DISPLAY_MOVED_NONE = 0,
20         DISPLAY_MOVED_ALL,
21         DISPLAY_MOVED_FOLLOW_DIFF,
22 };
23
24 /**
25  * @brief Endpoints of line connecting moved blocks
26  */
27 struct MovedLine
28 {
29         CPoint ptLeft;
30         CPoint ptRight;
31 };
32
33 typedef CList<MovedLine, MovedLine&> MOVEDLINE_LIST;
34
35 /**
36  * @brief A struct mapping difference lines to pixels in location pane.
37  * This structure maps one difference's line numbers to pixel locations in
38  * the location pane. The line numbers are "fixed" i.e. they are converted to
39  * word-wrapped absolute line numbers if needed.
40  */
41 struct DiffBlock
42 {
43         unsigned top_line; /**< First line of the difference. */
44         unsigned bottom_line; /**< Last line of the difference. */
45         unsigned top_coord; /**< X-coord of diff block begin. */
46         unsigned bottom_coord; /**< X-coord of diff block end. */
47         unsigned diff_index; /**< Index of difference in the original diff list. */
48         int op;
49 };
50
51 /** 
52  * @brief Class showing map of files.
53  * The location is a view showing two vertical bars. Each bar depicts one file
54  * in the file compare. The bars show a scaled view of the files. The
55  * difference areas are drawn with the same colors than in actual file compare.
56  * Also visible area of files is drawn as "shaded".
57  *
58  * These visualizations allow user to easily see a overall picture of the files
59  * in comparison. Using mouse it allows easy and fast moving in files.
60  */
61 class CLocationView : public CView
62 {
63 public:
64         CLocationView();
65         ~CLocationView();
66         DECLARE_DYNCREATE(CLocationView)
67         void SetConnectMovedBlocks(int displayMovedBlocks);
68         void UpdateVisiblePos(int nTopLine = -1, int nBottomLine = -1);
69         void SetFrameHwnd(HWND hwndFrame);
70         void ForceRecalculate();
71
72 protected:
73
74 // Overrides
75         // ClassWizard generated virtual function overrides
76         //{{AFX_VIRTUAL(CLocationView)
77         public:
78         virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
79         virtual void OnDraw(CDC* pDC);
80         //}}AFX_VIRTUAL
81
82 protected:
83         CMergeDoc* GetDocument();
84         void DrawRect(CDC* pDC, const CRect& r, COLORREF cr, BOOL bSelected = FALSE);
85         bool GotoLocation(const CPoint& point, bool bRealLine = true);
86         int GetLineFromYPos(int nYCoord, int bar, BOOL bRealLine = TRUE);
87         int IsInsideBar(const CRect& rc, const POINT& pt);
88         void DrawVisibleAreaRect(CDC* pDC, int nTopLine = -1, int nBottomLine = -1);
89         void DrawConnectLines(CDC* pDC);
90         void DrawDiffMarker(CDC* pDC, int yCoord);
91         void CalculateBars();
92         void CalculateBlocks();
93         void CalculateBlocksPixel(int nBlockStart, int nBlockEnd, int nBlockLength,
94                         int &nBeginY, int &nEndY);
95         void DrawBackground(CDC* pDC);
96
97 private:
98         int m_displayMovedBlocks; //*< Setting for displaying moved blocks */
99         double m_pixInLines; //*< How many pixels is one line in bars */
100         double m_lineInPix; //*< How many lines is one pixel?
101         CRect m_bar[3]; //*< Left/middle/riggt bar */
102         int m_visibleTop; //*< Top visible line for visible area indicator */
103         int m_visibleBottom; //*< Bottom visible line for visible area indicator */
104         int m_nSubLineCount[3]; //*< Cached subline count */
105         MOVEDLINE_LIST m_movedLines; //*< List of moved block connecting lines */
106         HWND m_hwndFrame; //*< Frame window handle */
107         std::unique_ptr<CBitmap> m_pSavedBackgroundBitmap; //*< Saved background */
108         bool m_bDrawn; //*< Is already drawn in location pane? */
109         std::vector<DiffBlock> m_diffBlocks; //*< List of pre-calculated diff blocks.
110         BOOL m_bRecalculateBlocks; //*< Recalculate diff blocks in next repaint.
111         CSize m_currentSize; //*< Current size of the panel.
112
113         // Generated message map functions
114 protected:
115         //{{AFX_MSG(CLocationView)
116         afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
117         afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
118         afx_msg void OnMouseMove(UINT nFlags, CPoint point);
119         afx_msg int  OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
120         afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
121         afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
122         afx_msg void OnClose();
123         afx_msg void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
124         afx_msg void OnSize(UINT nType, int cx, int cy);
125         afx_msg BOOL OnEraseBkgnd(CDC* pDC);
126         afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
127         afx_msg void OnUpdateFileSaveLeft(CCmdUI* pCmdUI);
128         afx_msg void OnUpdateFileSaveMiddle(CCmdUI* pCmdUI);
129         afx_msg void OnUpdateFileSaveRight(CCmdUI* pCmdUI);
130         //}}AFX_MSG
131         DECLARE_MESSAGE_MAP()
132 };
133
134 #ifndef _DEBUG  // debug version in DiffView.cpp
135 inline CMergeDoc* CLocationView::GetDocument()
136    { return reinterpret_cast<CMergeDoc*>(m_pDocument); }
137 #endif