xref: /aoo41x/main/sw/source/core/edit/edfmt.cxx (revision cdf0e10c)
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 "doc.hxx"
34 #include "editsh.hxx"
35 #include "swtable.hxx"
36 #include "pam.hxx"
37 #include <docary.hxx>
38 #include <fchrfmt.hxx>
39 #include <frmfmt.hxx>
40 #include <charfmt.hxx>
41 #include "ndtxt.hxx"    // Fuer GetXXXFmt
42 #include "hints.hxx"
43 
44 /*************************************
45  * Formate
46  *************************************/
47 // Char
48 // OPT: inline
49 
50 
51 sal_uInt16 SwEditShell::GetCharFmtCount() const
52 {
53 	return GetDoc()->GetCharFmts()->Count();
54 }
55 
56 
57 SwCharFmt& SwEditShell::GetCharFmt(sal_uInt16 nFmt) const
58 {
59 	return *((*(GetDoc()->GetCharFmts()))[nFmt]);
60 }
61 
62 
63 SwCharFmt* SwEditShell::GetCurCharFmt() const
64 {
65 	SwCharFmt *pFmt = 0;
66 	SfxItemSet aSet( GetDoc()->GetAttrPool(), RES_TXTATR_CHARFMT,
67 												RES_TXTATR_CHARFMT );
68 	const SfxPoolItem* pItem;
69     if( GetCurAttr( aSet ) && SFX_ITEM_SET ==
70 		aSet.GetItemState( RES_TXTATR_CHARFMT, sal_False, &pItem ) )
71 		pFmt = ((SwFmtCharFmt*)pItem)->GetCharFmt();
72 
73 	return pFmt;
74 }
75 
76 
77 void SwEditShell::FillByEx(SwCharFmt* pCharFmt, sal_Bool bReset)
78 {
79 	if ( bReset )
80     {
81         // --> OD 2007-01-25 #i73790# - method renamed
82         pCharFmt->ResetAllFmtAttr();
83         // <--
84     }
85 
86 	SwPaM* pPam = GetCrsr();
87 	const SwCntntNode* pCNd = pPam->GetCntntNode();
88 	if( pCNd->IsTxtNode() )
89 	{
90 		xub_StrLen nStt, nEnd;
91 		if( pPam->HasMark() )
92 		{
93 			const SwPosition* pPtPos = pPam->GetPoint();
94 			const SwPosition* pMkPos = pPam->GetMark();
95 			if( pPtPos->nNode == pMkPos->nNode )		// im selben Node ?
96 			{
97 				nStt = pPtPos->nContent.GetIndex();
98 				if( nStt < pMkPos->nContent.GetIndex() )
99 					nEnd = pMkPos->nContent.GetIndex();
100 				else
101 				{
102 					nEnd = nStt;
103 					nStt = pMkPos->nContent.GetIndex();
104 				}
105 			}
106 			else
107 			{
108 				nStt = pMkPos->nContent.GetIndex();
109 				if( pPtPos->nNode < pMkPos->nNode )
110 				{
111 					nEnd = nStt;
112 					nStt = 0;
113 				}
114 				else
115 					nEnd = ((SwTxtNode*)pCNd)->GetTxt().Len();
116 			}
117 		}
118 		else
119 			nStt = nEnd = pPam->GetPoint()->nContent.GetIndex();
120 
121 		SfxItemSet aSet( pDoc->GetAttrPool(),
122 							pCharFmt->GetAttrSet().GetRanges() );
123 		((SwTxtNode*)pCNd)->GetAttr( aSet, nStt, nEnd );
124         pCharFmt->SetFmtAttr( aSet );
125 	}
126     else if( pCNd->HasSwAttrSet() )
127         pCharFmt->SetFmtAttr( *pCNd->GetpSwAttrSet() );
128 }
129 
130 // Frm
131 sal_uInt16 SwEditShell::GetTblFrmFmtCount(sal_Bool bUsed) const
132 {
133 	return GetDoc()->GetTblFrmFmtCount(bUsed);
134 }
135 
136 SwFrmFmt& SwEditShell::GetTblFrmFmt(sal_uInt16 nFmt, sal_Bool bUsed ) const
137 {
138 	return GetDoc()->GetTblFrmFmt(nFmt, bUsed );
139 }
140 
141 String SwEditShell::GetUniqueTblName() const
142 {
143 	return GetDoc()->GetUniqueTblName();
144 }
145 
146 
147 SwCharFmt* SwEditShell::MakeCharFmt( const String& rName,
148 									SwCharFmt* pDerivedFrom )
149 {
150 	if( !pDerivedFrom )
151 		pDerivedFrom = GetDoc()->GetDfltCharFmt();
152 
153 	return GetDoc()->MakeCharFmt( rName, pDerivedFrom );
154 }
155 
156 //----------------------------------
157 // inlines im Product
158 
159 
160 SwTxtFmtColl* SwEditShell::GetTxtCollFromPool( sal_uInt16 nId )
161 {
162 	return GetDoc()->GetTxtCollFromPool( nId );
163 }
164 
165 
166 	// return das geforderte automatische  Format - Basis-Klasse !
167 SwFmt* SwEditShell::GetFmtFromPool( sal_uInt16 nId )
168 {
169 	return GetDoc()->GetFmtFromPool( nId );
170 }
171 
172 
173 SwPageDesc* SwEditShell::GetPageDescFromPool( sal_uInt16 nId )
174 {
175 	return GetDoc()->GetPageDescFromPool( nId );
176 }
177 
178 
179 sal_Bool SwEditShell::IsUsed( const SwModify& rModify ) const
180 {
181 	return pDoc->IsUsed( rModify );
182 }
183 
184 const SwFlyFrmFmt* SwEditShell::FindFlyByName( const String& rName, sal_uInt8 nNdTyp ) const
185 {
186 	return pDoc->FindFlyByName(rName, nNdTyp);
187 }
188 
189 SwCharFmt* SwEditShell::FindCharFmtByName( const String& rName ) const
190 {
191 	return pDoc->FindCharFmtByName( rName );
192 }
193 
194 SwTxtFmtColl* SwEditShell::FindTxtFmtCollByName( const String& rName ) const
195 {
196 	return pDoc->FindTxtFmtCollByName( rName );
197 }
198