OSDN Git Service

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