Fix compilation warnings
[TortoiseGit.git] / src / TortoiseMerge / XSplitter.cpp
blob8cb4e23e511e6dfc8c77164b236059519eb0d503
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006, 2011 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "XSplitter.h"
22 #ifdef _DEBUG
23 #define new DEBUG_NEW
24 #undef THIS_FILE
25 static char THIS_FILE[] = __FILE__;
26 #endif
28 CXSplitter::CXSplitter()
29 : m_bBarLocked(FALSE)
30 , m_nHiddenCol(-1)
31 , m_nHiddenRow(-1)
32 , m_pColOldSize(nullptr)
33 , m_pRowOldSize(nullptr)
34 , m_nOldCols(0)
35 , m_nOldRows(0)
39 CXSplitter::~CXSplitter()
41 delete [] m_pRowOldSize;
42 delete [] m_pColOldSize;
46 BEGIN_MESSAGE_MAP(CXSplitter, CSplitterWnd)
47 ON_WM_LBUTTONDBLCLK()
48 ON_WM_LBUTTONDOWN()
49 ON_WM_LBUTTONUP()
50 ON_WM_MOUSEMOVE()
51 ON_WM_SETCURSOR()
52 END_MESSAGE_MAP()
54 void CXSplitter::OnLButtonDown(UINT nFlags, CPoint point)
56 if (!m_bBarLocked)
57 CSplitterWnd::OnLButtonDown(nFlags, point);
60 void CXSplitter::OnMouseMove(UINT nFlags, CPoint point)
62 if (!m_bBarLocked)
63 CSplitterWnd::OnMouseMove(nFlags, point);
64 else
65 CWnd::OnMouseMove(nFlags, point);
68 BOOL CXSplitter::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
70 if (!m_bBarLocked)
71 return CWnd::OnSetCursor(pWnd, nHitTest, message);
73 return CSplitterWnd::OnSetCursor(pWnd, nHitTest, message);
76 BOOL CXSplitter::ReplaceView(int row, int col,CRuntimeClass * pViewClass,SIZE size)
78 CCreateContext context;
79 BOOL bSetActive;
81 if ((GetPane(row,col)->IsKindOf(pViewClass))==TRUE)
82 return FALSE;
84 // Get pointer to CDocument object so that it can be used in the creation
85 // process of the new view
86 CDocument * pDoc= ((CView *)GetPane(row,col))->GetDocument();
87 CView * pActiveView=GetParentFrame()->GetActiveView();
88 if (pActiveView==NULL || pActiveView==GetPane(row,col))
89 bSetActive=TRUE;
90 else
91 bSetActive=FALSE;
93 // set flag so that document will not be deleted when view is destroyed
94 pDoc->m_bAutoDelete=FALSE;
95 // Delete existing view
96 ((CView *) GetPane(row,col))->DestroyWindow();
97 // set flag back to default
98 pDoc->m_bAutoDelete=TRUE;
100 // Create new view
101 context.m_pNewViewClass=pViewClass;
102 context.m_pCurrentDoc=pDoc;
103 context.m_pNewDocTemplate=NULL;
104 context.m_pLastView=NULL;
105 context.m_pCurrentFrame=NULL;
107 CreateView(row,col,pViewClass,size, &context);
109 CView * pNewView= (CView *)GetPane(row,col);
111 if (bSetActive==TRUE)
112 GetParentFrame()->SetActiveView(pNewView);
114 RecalcLayout();
115 GetPane(row,col)->SendMessage(WM_PAINT);
117 return TRUE;
120 void CXSplitter::HideRow(int nRowHide)
122 ASSERT_VALID( this );
123 ASSERT( m_nRows > 1 );
124 ASSERT( nRowHide < m_nRows );
125 ASSERT( m_nHiddenRow == -1 );
126 m_nHiddenRow = nRowHide;
128 int nActiveRow, nActiveCol;
130 // if the nRow has an active window -- change it
131 if( GetActivePane( &nActiveRow, &nActiveCol ) != NULL )
133 if( nActiveRow == nRowHide )
135 if( ++nActiveRow >= m_nRows )
136 nActiveRow = 0;
137 SetActivePane( nActiveRow, nActiveCol );
141 // hide all nRow panes.
142 for( int nCol = 0; nCol < m_nCols; ++nCol )
144 CWnd* pPaneHide = GetPane( nRowHide, nCol );
145 ASSERT( pPaneHide != NULL );
147 pPaneHide->ShowWindow( SW_HIDE );
148 pPaneHide->SetDlgCtrlID( AFX_IDW_PANE_FIRST+nCol * 16+m_nRows );
150 for( int nRow = nRowHide+1; nRow < m_nRows; ++nRow )
152 CWnd* pPane = GetPane( nRow, nCol );
153 ASSERT( pPane != NULL );
155 pPane->SetDlgCtrlID( IdFromRowCol( nRow-1, nCol ));
159 m_nRows--;
160 m_pRowInfo[m_nRows].nCurSize = m_pRowInfo[nRowHide].nCurSize;
161 RecalcLayout();
164 void CXSplitter::ShowRow()
166 ASSERT_VALID( this );
167 ASSERT( m_nRows < m_nMaxRows );
168 ASSERT( m_nHiddenRow != -1 );
170 int nShowRow = m_nHiddenRow;
171 m_nHiddenRow = -1;
173 int cyNew = m_pRowInfo[m_nRows].nCurSize;
174 m_nRows++; // add a nRow
176 ASSERT( m_nRows == m_nMaxRows );
178 int nRow;
180 // Show the hidden nRow
181 for( int nCol = 0; nCol < m_nCols; ++nCol )
183 CWnd* pPaneShow = GetDlgItem( AFX_IDW_PANE_FIRST+nCol * 16+m_nRows );
184 ASSERT( pPaneShow != NULL );
185 pPaneShow->ShowWindow( SW_SHOWNA );
187 for( nRow = m_nRows - 2; nRow >= nShowRow; --nRow )
189 CWnd* pPane = GetPane( nRow, nCol );
190 ASSERT( pPane != NULL );
191 pPane->SetDlgCtrlID( IdFromRowCol( nRow + 1, nCol ));
194 pPaneShow->SetDlgCtrlID( IdFromRowCol( nShowRow, nCol ));
197 // new panes have been created -- recalculate layout
198 for( nRow = nShowRow+1; nRow < m_nRows; nRow++ )
199 m_pRowInfo[nRow].nIdealSize = m_pRowInfo[nRow - 1].nCurSize;
201 m_pRowInfo[nShowRow].nIdealSize = cyNew;
202 RecalcLayout();
205 void CXSplitter::HideColumn(int nColHide)
207 ASSERT_VALID( this );
208 ASSERT( m_nCols > 1 );
209 ASSERT( nColHide < m_nCols );
210 ASSERT( m_nHiddenCol == -1 );
211 m_nHiddenCol = nColHide;
213 // if the column has an active window -- change it
214 int nActiveRow, nActiveCol;
215 if( GetActivePane( &nActiveRow, &nActiveCol ) != NULL )
217 if( nActiveCol == nColHide )
219 if( ++nActiveCol >= m_nCols )
220 nActiveCol = 0;
221 SetActivePane( nActiveRow, nActiveCol );
225 // hide all column panes
226 for( int nRow = 0; nRow < m_nRows; nRow++)
228 CWnd* pPaneHide = GetPane(nRow, nColHide);
229 ASSERT( pPaneHide != NULL );
231 pPaneHide->ShowWindow(SW_HIDE);
232 pPaneHide->SetDlgCtrlID( AFX_IDW_PANE_FIRST+nRow * 16+m_nCols );
234 for( int nCol = nColHide + 1; nCol < m_nCols; nCol++ )
236 CWnd* pPane = GetPane( nRow, nCol );
237 ASSERT( pPane != NULL );
239 pPane->SetDlgCtrlID( IdFromRowCol( nRow, nCol - 1 ));
243 m_nCols--;
244 m_pColInfo[m_nCols].nCurSize = m_pColInfo[nColHide].nCurSize;
245 RecalcLayout();
248 void CXSplitter::ShowColumn()
250 ASSERT_VALID( this );
251 ASSERT( m_nCols < m_nMaxCols );
252 ASSERT( m_nHiddenCol != -1 );
254 int nShowCol = m_nHiddenCol;
255 m_nHiddenCol = -1;
257 int cxNew = m_pColInfo[m_nCols].nCurSize;
258 m_nCols++; // add a column
260 ASSERT( m_nCols == m_nMaxCols );
262 int nCol;
264 // Show the hidden column
265 for( int nRow = 0; nRow < m_nRows; ++nRow )
267 CWnd* pPaneShow = GetDlgItem( AFX_IDW_PANE_FIRST+nRow * 16+m_nCols );
268 ASSERT( pPaneShow != NULL );
269 pPaneShow->ShowWindow( SW_SHOWNA );
271 for( nCol = m_nCols - 2; nCol >= nShowCol; --nCol )
273 CWnd* pPane = GetPane( nRow, nCol );
274 ASSERT( pPane != NULL );
275 pPane->SetDlgCtrlID( IdFromRowCol( nRow, nCol + 1 ));
278 pPaneShow->SetDlgCtrlID( IdFromRowCol( nRow, nShowCol ));
281 // new panes have been created -- recalculate layout
282 for( nCol = nShowCol+1; nCol < m_nCols; nCol++ )
283 m_pColInfo[nCol].nIdealSize = m_pColInfo[nCol - 1].nCurSize;
285 m_pColInfo[nShowCol].nIdealSize = cxNew;
286 RecalcLayout();
289 void CXSplitter::CenterSplitter()
291 // get the size of all views
292 int width = 0;
293 int height = 0;
294 for( int nRow = 0; nRow < m_nRows; ++nRow )
296 height += m_pRowInfo[nRow].nCurSize;
298 for( int nCol = 0; nCol < m_nCols; ++nCol )
300 width += m_pColInfo[nCol].nCurSize;
303 // now set the sizes of the views
304 for( int nRow = 0; nRow < m_nRows; ++nRow )
306 m_pRowInfo[nRow].nIdealSize = height / m_nRows;
308 for( int nCol = 0; nCol < m_nCols; ++nCol )
310 m_pColInfo[nCol].nIdealSize = width / m_nCols;
312 RecalcLayout();
313 CopyRowAndColInfo();
316 void CXSplitter::OnLButtonDblClk( UINT /*nFlags*/, CPoint /*point*/ )
318 CenterSplitter();
321 void CXSplitter::OnLButtonUp(UINT nFlags, CPoint point)
323 CSplitterWnd::OnLButtonUp(nFlags, point);
324 CopyRowAndColInfo();
327 void CXSplitter::CopyRowAndColInfo()
329 delete [] m_pColOldSize; m_pColOldSize = nullptr;
330 delete [] m_pRowOldSize; m_pRowOldSize = nullptr;
332 m_nOldCols = m_nCols;
333 m_nOldRows = m_nRows;
334 if (m_nCols)
336 m_pColOldSize = new int[m_nCols];
337 for (int i = 0; i < m_nCols; ++i)
338 m_pColOldSize[i] = m_pColInfo[i].nCurSize;
340 if (m_nRows)
342 m_pRowOldSize = new int[m_nRows];
343 for (int i = 0; i < m_nRows; ++i)
344 m_pRowOldSize[i] = m_pRowInfo[i].nCurSize;