xref: /trunk/main/sw/source/core/crsr/trvlcol.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 
33 #include <crsrsh.hxx>
34 #include <doc.hxx>
35 #include <layfrm.hxx>
36 #include <cntfrm.hxx>
37 #include <swcrsr.hxx>
38 #include <viscrs.hxx>
39 #include <callnk.hxx>
40 
41 
42 
43 SwLayoutFrm* GetCurrColumn( const SwLayoutFrm* pLayFrm )
44 {
45     while( pLayFrm && !pLayFrm->IsColumnFrm() )
46         pLayFrm = pLayFrm->GetUpper();
47     return (SwLayoutFrm*)pLayFrm;
48 }
49 
50 
51 SwLayoutFrm* GetNextColumn( const SwLayoutFrm* pLayFrm )
52 {
53     SwLayoutFrm* pActCol = GetCurrColumn( pLayFrm );
54     return pActCol ? (SwLayoutFrm*)pActCol->GetNext() : 0;
55 }
56 
57 
58 SwLayoutFrm* GetPrevColumn( const SwLayoutFrm* pLayFrm )
59 {
60     SwLayoutFrm* pActCol = GetCurrColumn( pLayFrm );
61     return pActCol ? (SwLayoutFrm*)pActCol->GetPrev() : 0;
62 }
63 
64 
65 SwCntntFrm* GetColumnStt( const SwLayoutFrm* pColFrm )
66 {
67     return pColFrm ? (SwCntntFrm*)pColFrm->ContainsCntnt() : 0;
68 }
69 
70 
71 SwCntntFrm* GetColumnEnd( const SwLayoutFrm* pColFrm )
72 {
73     SwCntntFrm *pRet = GetColumnStt( pColFrm );
74     if( !pRet )
75         return 0;
76 
77     SwCntntFrm *pNxt = pRet->GetNextCntntFrm();
78     while( pNxt && pColFrm->IsAnLower( pNxt ) )
79     {
80         pRet = pNxt;
81         pNxt = pNxt->GetNextCntntFrm();
82     }
83     return pRet;
84 }
85 
86 
87 SwWhichColumn fnColumnPrev = &GetPrevColumn;
88 SwWhichColumn fnColumnCurr = &GetCurrColumn;
89 SwWhichColumn fnColumnNext = &GetNextColumn;
90 SwPosColumn fnColumnStart = &GetColumnStt;
91 SwPosColumn fnColumnEnd = &GetColumnEnd;
92 
93 
94 sal_Bool SwCrsrShell::MoveColumn( SwWhichColumn fnWhichCol, SwPosColumn fnPosCol )
95 {
96     sal_Bool bRet = sal_False;
97     if( !pTblCrsr )
98     {
99         SwLayoutFrm* pLayFrm = GetCurrFrm()->GetUpper();
100         if( pLayFrm && 0 != ( pLayFrm = (*fnWhichCol)( pLayFrm )) )
101         {
102             SwCntntFrm* pCnt = (*fnPosCol)( pLayFrm );
103             if( pCnt )
104             {
105                 SET_CURR_SHELL( this );
106                 SwCallLink aLk( *this );        // Crsr-Moves ueberwachen, evt. Link callen
107                 SwCrsrSaveState aSaveState( *pCurCrsr );
108 
109                 pCnt->Calc();                   // ???
110 
111                 Point aPt( pCnt->Frm().Pos() + pCnt->Prt().Pos() );
112                 if( fnPosCol == GetColumnEnd )
113                 {
114                     aPt.X() += pCnt->Prt().Width();
115                     aPt.Y() += pCnt->Prt().Height();
116                 }
117 
118                 pCnt->GetCrsrOfst( pCurCrsr->GetPoint(), aPt );
119 
120                 if( !pCurCrsr->IsInProtectTable( sal_True ) &&
121                     !pCurCrsr->IsSelOvr() )
122                 {
123                     UpdateCrsr();
124                     bRet = sal_True;
125                 }
126             }
127         }
128     }
129     return bRet;
130 }
131 
132 
133 
134