1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006 - Stefan Kueng
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.
20 #include "XSplitter.h"
25 static char THIS_FILE
[] = __FILE__
;
28 CXSplitter::CXSplitter()
35 CXSplitter::~CXSplitter()
40 BEGIN_MESSAGE_MAP(CXSplitter
, CSplitterWnd
)
46 void CXSplitter::OnLButtonDown(UINT nFlags
, CPoint point
)
49 CSplitterWnd::OnLButtonDown(nFlags
, point
);
52 void CXSplitter::OnMouseMove(UINT nFlags
, CPoint point
)
55 CSplitterWnd::OnMouseMove(nFlags
, point
);
57 CWnd::OnMouseMove(nFlags
, point
);
60 BOOL
CXSplitter::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
63 return CWnd::OnSetCursor(pWnd
, nHitTest
, message
);
65 return CSplitterWnd::OnSetCursor(pWnd
, nHitTest
, message
);
68 BOOL
CXSplitter::ReplaceView(int row
, int col
,CRuntimeClass
* pViewClass
,SIZE size
)
70 CCreateContext context
;
73 if ((GetPane(row
,col
)->IsKindOf(pViewClass
))==TRUE
)
76 // Get pointer to CDocument object so that it can be used in the creation
77 // process of the new view
78 CDocument
* pDoc
= ((CView
*)GetPane(row
,col
))->GetDocument();
79 CView
* pActiveView
=GetParentFrame()->GetActiveView();
80 if (pActiveView
==NULL
|| pActiveView
==GetPane(row
,col
))
85 // set flag so that document will not be deleted when view is destroyed
86 pDoc
->m_bAutoDelete
=FALSE
;
87 // Delete existing view
88 ((CView
*) GetPane(row
,col
))->DestroyWindow();
89 // set flag back to default
90 pDoc
->m_bAutoDelete
=TRUE
;
93 context
.m_pNewViewClass
=pViewClass
;
94 context
.m_pCurrentDoc
=pDoc
;
95 context
.m_pNewDocTemplate
=NULL
;
96 context
.m_pLastView
=NULL
;
97 context
.m_pCurrentFrame
=NULL
;
99 CreateView(row
,col
,pViewClass
,size
, &context
);
101 CView
* pNewView
= (CView
*)GetPane(row
,col
);
103 if (bSetActive
==TRUE
)
104 GetParentFrame()->SetActiveView(pNewView
);
107 GetPane(row
,col
)->SendMessage(WM_PAINT
);
112 void CXSplitter::HideRow(int nRowHide
)
114 ASSERT_VALID( this );
115 ASSERT( m_nRows
> 1 );
116 ASSERT( nRowHide
< m_nRows
);
117 ASSERT( m_nHiddenRow
== -1 );
118 m_nHiddenRow
= nRowHide
;
120 int nActiveRow
, nActiveCol
;
122 // if the nRow has an active window -- change it
123 if( GetActivePane( &nActiveRow
, &nActiveCol
) != NULL
)
125 if( nActiveRow
== nRowHide
)
127 if( ++nActiveRow
>= m_nRows
)
129 SetActivePane( nActiveRow
, nActiveCol
);
133 // hide all nRow panes.
134 for( int nCol
= 0; nCol
< m_nCols
; ++nCol
)
136 CWnd
* pPaneHide
= GetPane( nRowHide
, nCol
);
137 ASSERT( pPaneHide
!= NULL
);
139 pPaneHide
->ShowWindow( SW_HIDE
);
140 pPaneHide
->SetDlgCtrlID( AFX_IDW_PANE_FIRST
+nCol
* 16+m_nRows
);
142 for( int nRow
= nRowHide
+1; nRow
< m_nRows
; ++nRow
)
144 CWnd
* pPane
= GetPane( nRow
, nCol
);
145 ASSERT( pPane
!= NULL
);
147 pPane
->SetDlgCtrlID( IdFromRowCol( nRow
-1, nCol
));
152 m_pRowInfo
[m_nRows
].nCurSize
= m_pRowInfo
[nRowHide
].nCurSize
;
156 void CXSplitter::ShowRow()
158 ASSERT_VALID( this );
159 ASSERT( m_nRows
< m_nMaxRows
);
160 ASSERT( m_nHiddenRow
!= -1 );
162 int nShowRow
= m_nHiddenRow
;
165 int cyNew
= m_pRowInfo
[m_nRows
].nCurSize
;
166 m_nRows
++; // add a nRow
168 ASSERT( m_nRows
== m_nMaxRows
);
172 // Show the hidden nRow
173 for( int nCol
= 0; nCol
< m_nCols
; ++nCol
)
175 CWnd
* pPaneShow
= GetDlgItem( AFX_IDW_PANE_FIRST
+nCol
* 16+m_nRows
);
176 ASSERT( pPaneShow
!= NULL
);
177 pPaneShow
->ShowWindow( SW_SHOWNA
);
179 for( nRow
= m_nRows
- 2; nRow
>= nShowRow
; --nRow
)
181 CWnd
* pPane
= GetPane( nRow
, nCol
);
182 ASSERT( pPane
!= NULL
);
183 pPane
->SetDlgCtrlID( IdFromRowCol( nRow
+ 1, nCol
));
186 pPaneShow
->SetDlgCtrlID( IdFromRowCol( nShowRow
, nCol
));
189 // new panes have been created -- recalculate layout
190 for( nRow
= nShowRow
+1; nRow
< m_nRows
; nRow
++ )
191 m_pRowInfo
[nRow
].nIdealSize
= m_pRowInfo
[nRow
- 1].nCurSize
;
193 m_pRowInfo
[nShowRow
].nIdealSize
= cyNew
;
197 void CXSplitter::HideColumn(int nColHide
)
199 ASSERT_VALID( this );
200 ASSERT( m_nCols
> 1 );
201 ASSERT( nColHide
< m_nCols
);
202 ASSERT( m_nHiddenCol
== -1 );
203 m_nHiddenCol
= nColHide
;
205 // if the column has an active window -- change it
206 int nActiveRow
, nActiveCol
;
207 if( GetActivePane( &nActiveRow
, &nActiveCol
) != NULL
)
209 if( nActiveCol
== nColHide
)
211 if( ++nActiveCol
>= m_nCols
)
213 SetActivePane( nActiveRow
, nActiveCol
);
217 // hide all column panes
218 for( int nRow
= 0; nRow
< m_nRows
; nRow
++)
220 CWnd
* pPaneHide
= GetPane(nRow
, nColHide
);
221 ASSERT( pPaneHide
!= NULL
);
223 pPaneHide
->ShowWindow(SW_HIDE
);
224 pPaneHide
->SetDlgCtrlID( AFX_IDW_PANE_FIRST
+nRow
* 16+m_nCols
);
226 for( int nCol
= nColHide
+ 1; nCol
< m_nCols
; nCol
++ )
228 CWnd
* pPane
= GetPane( nRow
, nCol
);
229 ASSERT( pPane
!= NULL
);
231 pPane
->SetDlgCtrlID( IdFromRowCol( nRow
, nCol
- 1 ));
236 m_pColInfo
[m_nCols
].nCurSize
= m_pColInfo
[nColHide
].nCurSize
;
240 void CXSplitter::ShowColumn()
242 ASSERT_VALID( this );
243 ASSERT( m_nCols
< m_nMaxCols
);
244 ASSERT( m_nHiddenCol
!= -1 );
246 int nShowCol
= m_nHiddenCol
;
249 int cxNew
= m_pColInfo
[m_nCols
].nCurSize
;
250 m_nCols
++; // add a column
252 ASSERT( m_nCols
== m_nMaxCols
);
256 // Show the hidden column
257 for( int nRow
= 0; nRow
< m_nRows
; ++nRow
)
259 CWnd
* pPaneShow
= GetDlgItem( AFX_IDW_PANE_FIRST
+nRow
* 16+m_nCols
);
260 ASSERT( pPaneShow
!= NULL
);
261 pPaneShow
->ShowWindow( SW_SHOWNA
);
263 for( nCol
= m_nCols
- 2; nCol
>= nShowCol
; --nCol
)
265 CWnd
* pPane
= GetPane( nRow
, nCol
);
266 ASSERT( pPane
!= NULL
);
267 pPane
->SetDlgCtrlID( IdFromRowCol( nRow
, nCol
+ 1 ));
270 pPaneShow
->SetDlgCtrlID( IdFromRowCol( nRow
, nShowCol
));
273 // new panes have been created -- recalculate layout
274 for( nCol
= nShowCol
+1; nCol
< m_nCols
; nCol
++ )
275 m_pColInfo
[nCol
].nIdealSize
= m_pColInfo
[nCol
- 1].nCurSize
;
277 m_pColInfo
[nShowCol
].nIdealSize
= cxNew
;