OSDN Git Service

GitBlame Use command Line argument to open file
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / XSplitter.cpp
1 // TortoiseMerge - a Diff/Patch program\r
2 \r
3 // Copyright (C) 2006 - Stefan Kueng\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "XSplitter.h"\r
21 \r
22 #ifdef _DEBUG\r
23 #define new DEBUG_NEW\r
24 #undef THIS_FILE\r
25 static char THIS_FILE[] = __FILE__;\r
26 #endif\r
27 \r
28 CXSplitter::CXSplitter()\r
29 {\r
30         m_bBarLocked=FALSE;\r
31     m_nHiddenCol = -1;\r
32     m_nHiddenRow = -1;\r
33 }\r
34 \r
35 CXSplitter::~CXSplitter()\r
36 {\r
37 }\r
38 \r
39 \r
40 BEGIN_MESSAGE_MAP(CXSplitter, CSplitterWnd)\r
41         ON_WM_LBUTTONDOWN()\r
42         ON_WM_MOUSEMOVE()\r
43         ON_WM_SETCURSOR()\r
44 END_MESSAGE_MAP()\r
45 \r
46 void CXSplitter::OnLButtonDown(UINT nFlags, CPoint point) \r
47 {\r
48         if (!m_bBarLocked)\r
49                 CSplitterWnd::OnLButtonDown(nFlags, point);\r
50 }\r
51 \r
52 void CXSplitter::OnMouseMove(UINT nFlags, CPoint point) \r
53 {\r
54         if (!m_bBarLocked)\r
55                 CSplitterWnd::OnMouseMove(nFlags, point);\r
56         else\r
57                 CWnd::OnMouseMove(nFlags, point);\r
58 }\r
59 \r
60 BOOL CXSplitter::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) \r
61 {\r
62         if (!m_bBarLocked)\r
63                 return CWnd::OnSetCursor(pWnd, nHitTest, message);\r
64 \r
65         return CSplitterWnd::OnSetCursor(pWnd, nHitTest, message);\r
66 }\r
67 \r
68 BOOL CXSplitter::ReplaceView(int row, int col,CRuntimeClass * pViewClass,SIZE size)\r
69 {\r
70         CCreateContext context;\r
71         BOOL bSetActive;\r
72 \r
73         if ((GetPane(row,col)->IsKindOf(pViewClass))==TRUE)\r
74                 return FALSE;\r
75 \r
76         // Get pointer to CDocument object so that it can be used in the creation \r
77         // process of the new view\r
78         CDocument * pDoc= ((CView *)GetPane(row,col))->GetDocument();\r
79         CView * pActiveView=GetParentFrame()->GetActiveView();\r
80         if (pActiveView==NULL || pActiveView==GetPane(row,col))\r
81                 bSetActive=TRUE;\r
82         else\r
83                 bSetActive=FALSE;\r
84 \r
85         // set flag so that document will not be deleted when view is destroyed\r
86         pDoc->m_bAutoDelete=FALSE;    \r
87         // Delete existing view \r
88         ((CView *) GetPane(row,col))->DestroyWindow();\r
89         // set flag back to default \r
90         pDoc->m_bAutoDelete=TRUE;\r
91 \r
92         // Create new view                      \r
93         context.m_pNewViewClass=pViewClass;\r
94         context.m_pCurrentDoc=pDoc;\r
95         context.m_pNewDocTemplate=NULL;\r
96         context.m_pLastView=NULL;\r
97         context.m_pCurrentFrame=NULL;\r
98 \r
99         CreateView(row,col,pViewClass,size, &context);\r
100 \r
101         CView * pNewView= (CView *)GetPane(row,col);\r
102 \r
103         if (bSetActive==TRUE)\r
104                 GetParentFrame()->SetActiveView(pNewView);\r
105 \r
106         RecalcLayout(); \r
107         GetPane(row,col)->SendMessage(WM_PAINT);\r
108 \r
109         return TRUE;\r
110 }\r
111 \r
112 void CXSplitter::HideRow(int nRowHide)\r
113 {\r
114         ASSERT_VALID( this );\r
115         ASSERT( m_nRows > 1 );\r
116         ASSERT( nRowHide < m_nRows );\r
117         ASSERT( m_nHiddenRow == -1 );\r
118         m_nHiddenRow = nRowHide;\r
119 \r
120         int nActiveRow, nActiveCol;\r
121 \r
122         // if the nRow has an active window -- change it\r
123         if( GetActivePane( &nActiveRow, &nActiveCol ) != NULL )\r
124         {\r
125                 if( nActiveRow == nRowHide )\r
126                 {\r
127                         if( ++nActiveRow >= m_nRows )\r
128                                 nActiveRow = 0;\r
129                         SetActivePane( nActiveRow, nActiveCol );\r
130                 }\r
131         }\r
132 \r
133         // hide all nRow panes.\r
134         for( int nCol = 0; nCol < m_nCols; ++nCol )\r
135         {\r
136                 CWnd* pPaneHide = GetPane( nRowHide, nCol );\r
137                 ASSERT( pPaneHide != NULL );\r
138 \r
139                 pPaneHide->ShowWindow( SW_HIDE );\r
140                 pPaneHide->SetDlgCtrlID( AFX_IDW_PANE_FIRST+nCol * 16+m_nRows );\r
141 \r
142                 for( int nRow = nRowHide+1; nRow < m_nRows; ++nRow )\r
143                 {\r
144                         CWnd* pPane = GetPane( nRow, nCol );\r
145                         ASSERT( pPane != NULL );\r
146 \r
147                         pPane->SetDlgCtrlID( IdFromRowCol( nRow-1, nCol ));\r
148                 }\r
149         }\r
150 \r
151         m_nRows--;\r
152         m_pRowInfo[m_nRows].nCurSize = m_pRowInfo[nRowHide].nCurSize;\r
153         RecalcLayout();\r
154 }\r
155 \r
156 void CXSplitter::ShowRow()\r
157 {\r
158         ASSERT_VALID( this );\r
159         ASSERT( m_nRows < m_nMaxRows );\r
160         ASSERT( m_nHiddenRow != -1 );\r
161 \r
162         int nShowRow = m_nHiddenRow;\r
163         m_nHiddenRow = -1;\r
164 \r
165         int cyNew = m_pRowInfo[m_nRows].nCurSize;\r
166         m_nRows++;  // add a nRow\r
167 \r
168         ASSERT( m_nRows == m_nMaxRows );\r
169 \r
170         int nRow;\r
171 \r
172         // Show the hidden nRow\r
173         for( int nCol = 0; nCol < m_nCols; ++nCol )\r
174         {\r
175                 CWnd* pPaneShow = GetDlgItem( AFX_IDW_PANE_FIRST+nCol * 16+m_nRows );\r
176                 ASSERT( pPaneShow != NULL );\r
177                 pPaneShow->ShowWindow( SW_SHOWNA );\r
178 \r
179                 for( nRow = m_nRows - 2; nRow >= nShowRow; --nRow )\r
180                 {\r
181                         CWnd* pPane = GetPane( nRow, nCol );\r
182                         ASSERT( pPane != NULL );\r
183                         pPane->SetDlgCtrlID( IdFromRowCol( nRow + 1, nCol ));\r
184                 }\r
185 \r
186                 pPaneShow->SetDlgCtrlID( IdFromRowCol( nShowRow, nCol ));\r
187         }\r
188 \r
189         // new panes have been created -- recalculate layout\r
190         for( nRow = nShowRow+1; nRow < m_nRows; nRow++ )\r
191                 m_pRowInfo[nRow].nIdealSize = m_pRowInfo[nRow - 1].nCurSize;\r
192 \r
193         m_pRowInfo[nShowRow].nIdealSize = cyNew;\r
194         RecalcLayout();\r
195 }\r
196 \r
197 void CXSplitter::HideColumn(int nColHide)\r
198 {\r
199         ASSERT_VALID( this );\r
200         ASSERT( m_nCols > 1 );\r
201         ASSERT( nColHide < m_nCols );\r
202         ASSERT( m_nHiddenCol == -1 );\r
203         m_nHiddenCol = nColHide;\r
204 \r
205         // if the column has an active window -- change it\r
206         int nActiveRow, nActiveCol;\r
207         if( GetActivePane( &nActiveRow, &nActiveCol ) != NULL )\r
208         {\r
209                 if( nActiveCol == nColHide )\r
210                 {\r
211                         if( ++nActiveCol >= m_nCols )\r
212                                 nActiveCol = 0;\r
213                         SetActivePane( nActiveRow, nActiveCol );\r
214                 }\r
215         }\r
216 \r
217         // hide all column panes\r
218         for( int nRow = 0; nRow < m_nRows; nRow++)\r
219         {\r
220                 CWnd* pPaneHide = GetPane(nRow, nColHide);\r
221                 ASSERT( pPaneHide != NULL );\r
222 \r
223                 pPaneHide->ShowWindow(SW_HIDE);\r
224                 pPaneHide->SetDlgCtrlID( AFX_IDW_PANE_FIRST+nRow * 16+m_nCols );\r
225 \r
226                 for( int nCol = nColHide + 1; nCol < m_nCols; nCol++ )\r
227                 {\r
228                         CWnd* pPane = GetPane( nRow, nCol );\r
229                         ASSERT( pPane != NULL );\r
230 \r
231                         pPane->SetDlgCtrlID( IdFromRowCol( nRow, nCol - 1 ));\r
232                 }\r
233         }\r
234 \r
235         m_nCols--;\r
236         m_pColInfo[m_nCols].nCurSize = m_pColInfo[nColHide].nCurSize;\r
237         RecalcLayout();\r
238 }\r
239 \r
240 void CXSplitter::ShowColumn()\r
241 {\r
242         ASSERT_VALID( this );\r
243         ASSERT( m_nCols < m_nMaxCols );\r
244         ASSERT( m_nHiddenCol != -1 );\r
245 \r
246         int nShowCol = m_nHiddenCol;\r
247         m_nHiddenCol = -1;\r
248 \r
249         int cxNew = m_pColInfo[m_nCols].nCurSize;\r
250         m_nCols++;  // add a column\r
251 \r
252         ASSERT( m_nCols == m_nMaxCols );\r
253 \r
254         int nCol;\r
255 \r
256         // Show the hidden column\r
257         for( int nRow = 0; nRow < m_nRows; ++nRow )\r
258         {\r
259                 CWnd* pPaneShow = GetDlgItem( AFX_IDW_PANE_FIRST+nRow * 16+m_nCols );\r
260                 ASSERT( pPaneShow != NULL );\r
261                 pPaneShow->ShowWindow( SW_SHOWNA );\r
262 \r
263                 for( nCol = m_nCols - 2; nCol >= nShowCol; --nCol )\r
264                 {\r
265                         CWnd* pPane = GetPane( nRow, nCol );\r
266                         ASSERT( pPane != NULL );\r
267                         pPane->SetDlgCtrlID( IdFromRowCol( nRow, nCol + 1 ));\r
268                 }\r
269 \r
270                 pPaneShow->SetDlgCtrlID( IdFromRowCol( nRow, nShowCol ));\r
271         }\r
272 \r
273         // new panes have been created -- recalculate layout\r
274         for( nCol = nShowCol+1; nCol < m_nCols; nCol++ )\r
275                 m_pColInfo[nCol].nIdealSize = m_pColInfo[nCol - 1].nCurSize;\r
276 \r
277         m_pColInfo[nShowCol].nIdealSize = cxNew;\r
278         RecalcLayout();\r
279 }\r
280 \r