merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / edit / edfmt.cxx
blobd3bcf716d43d0e868147d70ca781f6212194cd13
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: edfmt.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include "doc.hxx"
37 #include "editsh.hxx"
38 #include "swtable.hxx"
39 #include "pam.hxx"
40 #include <docary.hxx>
41 #include <fchrfmt.hxx>
42 #include <frmfmt.hxx>
43 #include <charfmt.hxx>
44 #include "ndtxt.hxx" // Fuer GetXXXFmt
45 #include "hints.hxx"
47 /*************************************
48 * Formate
49 *************************************/
50 // Char
51 // OPT: inline
54 USHORT SwEditShell::GetCharFmtCount() const
56 return GetDoc()->GetCharFmts()->Count();
60 SwCharFmt& SwEditShell::GetCharFmt(USHORT nFmt) const
62 return *((*(GetDoc()->GetCharFmts()))[nFmt]);
66 SwCharFmt* SwEditShell::GetCurCharFmt() const
68 SwCharFmt *pFmt = 0;
69 SfxItemSet aSet( GetDoc()->GetAttrPool(), RES_TXTATR_CHARFMT,
70 RES_TXTATR_CHARFMT );
71 const SfxPoolItem* pItem;
72 if( GetCurAttr( aSet ) && SFX_ITEM_SET ==
73 aSet.GetItemState( RES_TXTATR_CHARFMT, FALSE, &pItem ) )
74 pFmt = ((SwFmtCharFmt*)pItem)->GetCharFmt();
76 return pFmt;
80 void SwEditShell::FillByEx(SwCharFmt* pCharFmt, BOOL bReset)
82 if ( bReset )
84 // --> OD 2007-01-25 #i73790# - method renamed
85 pCharFmt->ResetAllFmtAttr();
86 // <--
89 SwPaM* pPam = GetCrsr();
90 const SwCntntNode* pCNd = pPam->GetCntntNode();
91 if( pCNd->IsTxtNode() )
93 xub_StrLen nStt, nEnd;
94 if( pPam->HasMark() )
96 const SwPosition* pPtPos = pPam->GetPoint();
97 const SwPosition* pMkPos = pPam->GetMark();
98 if( pPtPos->nNode == pMkPos->nNode ) // im selben Node ?
100 nStt = pPtPos->nContent.GetIndex();
101 if( nStt < pMkPos->nContent.GetIndex() )
102 nEnd = pMkPos->nContent.GetIndex();
103 else
105 nEnd = nStt;
106 nStt = pMkPos->nContent.GetIndex();
109 else
111 nStt = pMkPos->nContent.GetIndex();
112 if( pPtPos->nNode < pMkPos->nNode )
114 nEnd = nStt;
115 nStt = 0;
117 else
118 nEnd = ((SwTxtNode*)pCNd)->GetTxt().Len();
121 else
122 nStt = nEnd = pPam->GetPoint()->nContent.GetIndex();
124 SfxItemSet aSet( pDoc->GetAttrPool(),
125 pCharFmt->GetAttrSet().GetRanges() );
126 ((SwTxtNode*)pCNd)->GetAttr( aSet, nStt, nEnd );
127 pCharFmt->SetFmtAttr( aSet );
129 else if( pCNd->HasSwAttrSet() )
130 pCharFmt->SetFmtAttr( *pCNd->GetpSwAttrSet() );
133 // Frm
134 USHORT SwEditShell::GetTblFrmFmtCount(BOOL bUsed) const
136 return GetDoc()->GetTblFrmFmtCount(bUsed);
139 SwFrmFmt& SwEditShell::GetTblFrmFmt(USHORT nFmt, BOOL bUsed ) const
141 return GetDoc()->GetTblFrmFmt(nFmt, bUsed );
144 String SwEditShell::GetUniqueTblName() const
146 return GetDoc()->GetUniqueTblName();
150 SwCharFmt* SwEditShell::MakeCharFmt( const String& rName,
151 SwCharFmt* pDerivedFrom )
153 if( !pDerivedFrom )
154 pDerivedFrom = GetDoc()->GetDfltCharFmt();
156 return GetDoc()->MakeCharFmt( rName, pDerivedFrom );
159 //----------------------------------
160 // inlines im Product
163 SwTxtFmtColl* SwEditShell::GetTxtCollFromPool( USHORT nId )
165 return GetDoc()->GetTxtCollFromPool( nId );
169 // return das geforderte automatische Format - Basis-Klasse !
170 SwFmt* SwEditShell::GetFmtFromPool( USHORT nId )
172 return GetDoc()->GetFmtFromPool( nId );
176 SwPageDesc* SwEditShell::GetPageDescFromPool( USHORT nId )
178 return GetDoc()->GetPageDescFromPool( nId );
182 BOOL SwEditShell::IsUsed( const SwModify& rModify ) const
184 return pDoc->IsUsed( rModify );
187 const SwFlyFrmFmt* SwEditShell::FindFlyByName( const String& rName, BYTE nNdTyp ) const
189 return pDoc->FindFlyByName(rName, nNdTyp);
192 SwCharFmt* SwEditShell::FindCharFmtByName( const String& rName ) const
194 return pDoc->FindCharFmtByName( rName );
197 SwTxtFmtColl* SwEditShell::FindTxtFmtCollByName( const String& rName ) const
199 return pDoc->FindTxtFmtCollByName( rName );