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()
39 BEGIN_MESSAGE_MAP(CXSplitter
, CSplitterWnd
)
45 void CXSplitter::OnLButtonDown(UINT nFlags
, CPoint point
)
48 CSplitterWnd::OnLButtonDown(nFlags
, point
);
51 void CXSplitter::OnMouseMove(UINT nFlags
, CPoint point
)
54 CSplitterWnd::OnMouseMove(nFlags
, point
);
56 CWnd::OnMouseMove(nFlags
, point
);
59 BOOL
CXSplitter::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
62 return CWnd::OnSetCursor(pWnd
, nHitTest
, message
);
64 return CSplitterWnd::OnSetCursor(pWnd
, nHitTest
, message
);
67 BOOL
CXSplitter::ReplaceView(int row
, int col
,CRuntimeClass
* pViewClass
,SIZE size
)
69 CCreateContext context
;
72 if ((GetPane(row
,col
)->IsKindOf(pViewClass
))==TRUE
)
75 // Get pointer to CDocument object so that it can be used in the creation
76 // process of the new view
77 CDocument
* pDoc
= ((CView
*)GetPane(row
,col
))->GetDocument();
78 CView
* pActiveView
=GetParentFrame()->GetActiveView();
79 if (pActiveView
==NULL
|| pActiveView
==GetPane(row
,col
))
84 // set flag so that document will not be deleted when view is destroyed
85 pDoc
->m_bAutoDelete
=FALSE
;
86 // Delete existing view
87 ((CView
*) GetPane(row
,col
))->DestroyWindow();
88 // set flag back to default
89 pDoc
->m_bAutoDelete
=TRUE
;
92 context
.m_pNewViewClass
=pViewClass
;
93 context
.m_pCurrentDoc
=pDoc
;
94 context
.m_pNewDocTemplate
=NULL
;
95 context
.m_pLastView
=NULL
;
96 context
.m_pCurrentFrame
=NULL
;
98 CreateView(row
,col
,pViewClass
,size
, &context
);
100 CView
* pNewView
= (CView
*)GetPane(row
,col
);
102 if (bSetActive
==TRUE
)
103 GetParentFrame()->SetActiveView(pNewView
);
106 GetPane(row
,col
)->SendMessage(WM_PAINT
);
111 void CXSplitter::HideRow(int nRowHide
)
113 ASSERT_VALID( this );
114 ASSERT( m_nRows
> 1 );
115 ASSERT( nRowHide
< m_nRows
);
116 ASSERT( m_nHiddenRow
== -1 );
117 m_nHiddenRow
= nRowHide
;
119 int nActiveRow
, nActiveCol
;
121 // if the nRow has an active window -- change it
122 if( GetActivePane( &nActiveRow
, &nActiveCol
) != NULL
)
124 if( nActiveRow
== nRowHide
)
126 if( ++nActiveRow
>= m_nRows
)
128 SetActivePane( nActiveRow
, nActiveCol
);
132 // hide all nRow panes.
133 for( int nCol
= 0; nCol
< m_nCols
; ++nCol
)
135 CWnd
* pPaneHide
= GetPane( nRowHide
, nCol
);
136 ASSERT( pPaneHide
!= NULL
);
138 pPaneHide
->ShowWindow( SW_HIDE
);
139 pPaneHide
->SetDlgCtrlID( AFX_IDW_PANE_FIRST
+nCol
* 16+m_nRows
);
141 for( int nRow
= nRowHide
+1; nRow
< m_nRows
; ++nRow
)
143 CWnd
* pPane
= GetPane( nRow
, nCol
);
144 ASSERT( pPane
!= NULL
);
146 pPane
->SetDlgCtrlID( IdFromRowCol( nRow
-1, nCol
));
151 m_pRowInfo
[m_nRows
].nCurSize
= m_pRowInfo
[nRowHide
].nCurSize
;
155 void CXSplitter::ShowRow()
157 ASSERT_VALID( this );
158 ASSERT( m_nRows
< m_nMaxRows
);
159 ASSERT( m_nHiddenRow
!= -1 );
161 int nShowRow
= m_nHiddenRow
;
164 int cyNew
= m_pRowInfo
[m_nRows
].nCurSize
;
165 m_nRows
++; // add a nRow
167 ASSERT( m_nRows
== m_nMaxRows
);
171 // Show the hidden nRow
172 for( int nCol
= 0; nCol
< m_nCols
; ++nCol
)
174 CWnd
* pPaneShow
= GetDlgItem( AFX_IDW_PANE_FIRST
+nCol
* 16+m_nRows
);
175 ASSERT( pPaneShow
!= NULL
);
176 pPaneShow
->ShowWindow( SW_SHOWNA
);
178 for( nRow
= m_nRows
- 2; nRow
>= nShowRow
; --nRow
)
180 CWnd
* pPane
= GetPane( nRow
, nCol
);
181 ASSERT( pPane
!= NULL
);
182 pPane
->SetDlgCtrlID( IdFromRowCol( nRow
+ 1, nCol
));
185 pPaneShow
->SetDlgCtrlID( IdFromRowCol( nShowRow
, nCol
));
188 // new panes have been created -- recalculate layout
189 for( nRow
= nShowRow
+1; nRow
< m_nRows
; nRow
++ )
190 m_pRowInfo
[nRow
].nIdealSize
= m_pRowInfo
[nRow
- 1].nCurSize
;
192 m_pRowInfo
[nShowRow
].nIdealSize
= cyNew
;
196 void CXSplitter::HideColumn(int nColHide
)
198 ASSERT_VALID( this );
199 ASSERT( m_nCols
> 1 );
200 ASSERT( nColHide
< m_nCols
);
201 ASSERT( m_nHiddenCol
== -1 );
202 m_nHiddenCol
= nColHide
;
204 // if the column has an active window -- change it
205 int nActiveRow
, nActiveCol
;
206 if( GetActivePane( &nActiveRow
, &nActiveCol
) != NULL
)
208 if( nActiveCol
== nColHide
)
210 if( ++nActiveCol
>= m_nCols
)
212 SetActivePane( nActiveRow
, nActiveCol
);
216 // hide all column panes
217 for( int nRow
= 0; nRow
< m_nRows
; nRow
++)
219 CWnd
* pPaneHide
= GetPane(nRow
, nColHide
);
220 ASSERT( pPaneHide
!= NULL
);
222 pPaneHide
->ShowWindow(SW_HIDE
);
223 pPaneHide
->SetDlgCtrlID( AFX_IDW_PANE_FIRST
+nRow
* 16+m_nCols
);
225 for( int nCol
= nColHide
+ 1; nCol
< m_nCols
; nCol
++ )
227 CWnd
* pPane
= GetPane( nRow
, nCol
);
228 ASSERT( pPane
!= NULL
);
230 pPane
->SetDlgCtrlID( IdFromRowCol( nRow
, nCol
- 1 ));
235 m_pColInfo
[m_nCols
].nCurSize
= m_pColInfo
[nColHide
].nCurSize
;
239 void CXSplitter::ShowColumn()
241 ASSERT_VALID( this );
242 ASSERT( m_nCols
< m_nMaxCols
);
243 ASSERT( m_nHiddenCol
!= -1 );
245 int nShowCol
= m_nHiddenCol
;
248 int cxNew
= m_pColInfo
[m_nCols
].nCurSize
;
249 m_nCols
++; // add a column
251 ASSERT( m_nCols
== m_nMaxCols
);
255 // Show the hidden column
256 for( int nRow
= 0; nRow
< m_nRows
; ++nRow
)
258 CWnd
* pPaneShow
= GetDlgItem( AFX_IDW_PANE_FIRST
+nRow
* 16+m_nCols
);
259 ASSERT( pPaneShow
!= NULL
);
260 pPaneShow
->ShowWindow( SW_SHOWNA
);
262 for( nCol
= m_nCols
- 2; nCol
>= nShowCol
; --nCol
)
264 CWnd
* pPane
= GetPane( nRow
, nCol
);
265 ASSERT( pPane
!= NULL
);
266 pPane
->SetDlgCtrlID( IdFromRowCol( nRow
, nCol
+ 1 ));
269 pPaneShow
->SetDlgCtrlID( IdFromRowCol( nRow
, nShowCol
));
272 // new panes have been created -- recalculate layout
273 for( nCol
= nShowCol
+1; nCol
< m_nCols
; nCol
++ )
274 m_pColInfo
[nCol
].nIdealSize
= m_pColInfo
[nCol
- 1].nCurSize
;
276 m_pColInfo
[nShowCol
].nIdealSize
= cxNew
;