xref: /aoo41x/main/sw/source/core/edit/edattr.cxx (revision 69a74367)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <editeng/tstpitem.hxx>
31cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
32cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx>
33cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hdl>
34cdf0e10cSrcweir #include <txatbase.hxx>
35cdf0e10cSrcweir #include <txtftn.hxx>
36cdf0e10cSrcweir #include <fmtftn.hxx>
37cdf0e10cSrcweir #include <editsh.hxx>
38cdf0e10cSrcweir #include <edimp.hxx>	// fuer MACROS
39cdf0e10cSrcweir #include <doc.hxx>
40cdf0e10cSrcweir #include <swundo.hxx>	// fuer UNDO-Ids
41cdf0e10cSrcweir #include <ndtxt.hxx>
42cdf0e10cSrcweir #include <ftnidx.hxx>
43cdf0e10cSrcweir #include <expfld.hxx>
44cdf0e10cSrcweir #include <rootfrm.hxx>
45cdf0e10cSrcweir #include <cntfrm.hxx>
46cdf0e10cSrcweir #include <breakit.hxx>
47cdf0e10cSrcweir #include <txtfld.hxx>
48cdf0e10cSrcweir #include <fmtfld.hxx>
49cdf0e10cSrcweir #include <crsskip.hxx>
50cdf0e10cSrcweir #include <txtfrm.hxx>		// SwTxtFrm
51cdf0e10cSrcweir #include <scriptinfo.hxx>
52cdf0e10cSrcweir #include <svl/ctloptions.hxx>
53cdf0e10cSrcweir #include <charfmt.hxx>  // #i27615#
54cdf0e10cSrcweir #include <numrule.hxx>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir /*************************************
58cdf0e10cSrcweir  * harte Formatierung (Attribute)
59cdf0e10cSrcweir  *************************************/
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // wenn Selektion groesser Max Nodes oder mehr als Max Selektionen
62cdf0e10cSrcweir // => keine Attribute
getMaxLookup()63cdf0e10cSrcweir const sal_uInt16& getMaxLookup()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	static const sal_uInt16 nMaxLookup = 1000;
66cdf0e10cSrcweir 	return nMaxLookup;
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir // --> OD 2008-01-16 #newlistlevelattrs#
GetCurAttr(SfxItemSet & rSet,const bool bMergeIndentValuesOfNumRule) const70cdf0e10cSrcweir sal_Bool SwEditShell::GetCurAttr( SfxItemSet& rSet,
71cdf0e10cSrcweir                               const bool bMergeIndentValuesOfNumRule ) const
72cdf0e10cSrcweir // <--
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 	if( GetCrsrCnt() > getMaxLookup() )
75cdf0e10cSrcweir 	{
76cdf0e10cSrcweir 		rSet.InvalidateAllItems();
77cdf0e10cSrcweir 		return sal_False;
78cdf0e10cSrcweir 	}
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	SfxItemSet aSet( *rSet.GetPool(), rSet.GetRanges() );
81cdf0e10cSrcweir 	SfxItemSet *pSet = &rSet;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	FOREACHPAM_START(this)
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         // #i27615# if the cursor is in front of the numbering label
86cdf0e10cSrcweir         // the attributes to get are those from the numbering format.
87cdf0e10cSrcweir         if (PCURCRSR->IsInFrontOfLabel())
88cdf0e10cSrcweir         {
89cdf0e10cSrcweir             SwTxtNode * pTxtNd =
90cdf0e10cSrcweir                 PCURCRSR->GetPoint()->nNode.GetNode().GetTxtNode();
91cdf0e10cSrcweir 
92cdf0e10cSrcweir             if (pTxtNd)
93cdf0e10cSrcweir             {
94cdf0e10cSrcweir                 SwNumRule * pNumRule = pTxtNd->GetNumRule();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir                 if (pNumRule)
97cdf0e10cSrcweir                 {
98cdf0e10cSrcweir                     const String & aCharFmtName =
99cdf0e10cSrcweir                         pNumRule->Get(static_cast<sal_uInt16>(pTxtNd->GetActualListLevel())).GetCharFmtName();
100cdf0e10cSrcweir                     SwCharFmt * pCharFmt =
101cdf0e10cSrcweir                         GetDoc()->FindCharFmtByName(aCharFmtName);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir                     if (pCharFmt)
104cdf0e10cSrcweir                         rSet.Put(pCharFmt->GetAttrSet());
105cdf0e10cSrcweir                 }
106cdf0e10cSrcweir             }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir             continue;
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		sal_uLong nSttNd = PCURCRSR->GetMark()->nNode.GetIndex(),
112cdf0e10cSrcweir 			  nEndNd = PCURCRSR->GetPoint()->nNode.GetIndex();
113cdf0e10cSrcweir 		xub_StrLen nSttCnt = PCURCRSR->GetMark()->nContent.GetIndex(),
114cdf0e10cSrcweir 				   nEndCnt = PCURCRSR->GetPoint()->nContent.GetIndex();
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		if( nSttNd > nEndNd || ( nSttNd == nEndNd && nSttCnt > nEndCnt ))
117cdf0e10cSrcweir 		{
118cdf0e10cSrcweir 			sal_uLong nTmp = nSttNd; nSttNd = nEndNd; nEndNd = nTmp;
119cdf0e10cSrcweir 			nTmp = nSttCnt; nSttCnt = nEndCnt; nEndCnt = (xub_StrLen)nTmp;
120cdf0e10cSrcweir 		}
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 		if( nEndNd - nSttNd >= getMaxLookup() )
123cdf0e10cSrcweir 		{
124cdf0e10cSrcweir 			rSet.ClearItem();
125cdf0e10cSrcweir 			rSet.InvalidateAllItems();
126cdf0e10cSrcweir 			return sal_False;
127cdf0e10cSrcweir 		}
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		// beim 1.Node traegt der Node die Werte in den GetSet ein (Initial)
130cdf0e10cSrcweir 		// alle weiteren Nodes werden zum GetSet zu gemergt
131cdf0e10cSrcweir 		for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
132cdf0e10cSrcweir 		{
133cdf0e10cSrcweir 			SwNode* pNd = GetDoc()->GetNodes()[ n ];
134cdf0e10cSrcweir 			switch( pNd->GetNodeType() )
135cdf0e10cSrcweir 			{
136cdf0e10cSrcweir 			case ND_TEXTNODE:
137cdf0e10cSrcweir 				{
138cdf0e10cSrcweir 					xub_StrLen nStt = n == nSttNd ? nSttCnt : 0,
139cdf0e10cSrcweir 						   	   nEnd = n == nEndNd ? nEndCnt
140cdf0e10cSrcweir 										: ((SwTxtNode*)pNd)->GetTxt().Len();
141cdf0e10cSrcweir                     // --> OD 2008-01-16 #newlistlevelattrs#
142cdf0e10cSrcweir                     ((SwTxtNode*)pNd)->GetAttr( *pSet, nStt, nEnd,
143cdf0e10cSrcweir                                                 sal_False, sal_True,
144cdf0e10cSrcweir                                                 bMergeIndentValuesOfNumRule );
145cdf0e10cSrcweir                     // <--
146cdf0e10cSrcweir 				}
147cdf0e10cSrcweir 				break;
148cdf0e10cSrcweir 			case ND_GRFNODE:
149cdf0e10cSrcweir 			case ND_OLENODE:
150cdf0e10cSrcweir 				((SwCntntNode*)pNd)->GetAttr( *pSet );
151cdf0e10cSrcweir 				break;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 			default:
154cdf0e10cSrcweir 				pNd = 0;
155cdf0e10cSrcweir 			}
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 			if( pNd )
158cdf0e10cSrcweir 			{
159cdf0e10cSrcweir 				if( pSet != &rSet )
160cdf0e10cSrcweir 					rSet.MergeValues( aSet );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 				if( aSet.Count() )
163cdf0e10cSrcweir 					aSet.ClearItem();
164cdf0e10cSrcweir 			}
165cdf0e10cSrcweir 			pSet = &aSet;
166cdf0e10cSrcweir 		}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	FOREACHPAM_END()
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	return sal_True;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
GetCurTxtFmtColl() const173cdf0e10cSrcweir SwTxtFmtColl* SwEditShell::GetCurTxtFmtColl() const
174cdf0e10cSrcweir {
175cdf0e10cSrcweir 	SwTxtFmtColl *pFmt = 0;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	if ( GetCrsrCnt() > getMaxLookup() )
178cdf0e10cSrcweir 		return 0;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	FOREACHPAM_START(this)
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		sal_uLong nSttNd = PCURCRSR->GetMark()->nNode.GetIndex(),
183cdf0e10cSrcweir 			  nEndNd = PCURCRSR->GetPoint()->nNode.GetIndex();
184cdf0e10cSrcweir 		xub_StrLen nSttCnt = PCURCRSR->GetMark()->nContent.GetIndex(),
185cdf0e10cSrcweir 				   nEndCnt = PCURCRSR->GetPoint()->nContent.GetIndex();
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 		if( nSttNd > nEndNd || ( nSttNd == nEndNd && nSttCnt > nEndCnt ))
188cdf0e10cSrcweir 		{
189cdf0e10cSrcweir 			sal_uLong nTmp = nSttNd; nSttNd = nEndNd; nEndNd = nTmp;
190cdf0e10cSrcweir 			nTmp = nSttCnt; nSttCnt = nEndCnt; nEndCnt = (xub_StrLen)nTmp;
191cdf0e10cSrcweir 		}
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		if( nEndNd - nSttNd >= getMaxLookup() )
194cdf0e10cSrcweir 		{
195cdf0e10cSrcweir 			pFmt = 0;
196cdf0e10cSrcweir 			break;
197cdf0e10cSrcweir 		}
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 		for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
200cdf0e10cSrcweir 		{
201cdf0e10cSrcweir 			SwNode* pNd = GetDoc()->GetNodes()[ n ];
202cdf0e10cSrcweir 			if( pNd->IsTxtNode() )
203cdf0e10cSrcweir 			{
204cdf0e10cSrcweir 				if( !pFmt )
205cdf0e10cSrcweir 					pFmt = ((SwTxtNode*)pNd)->GetTxtColl();
206cdf0e10cSrcweir 				else if( pFmt == ((SwTxtNode*)pNd)->GetTxtColl() ) // ???
207cdf0e10cSrcweir 					break;
208cdf0e10cSrcweir 			}
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	FOREACHPAM_END()
212cdf0e10cSrcweir 	return pFmt;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 
GetCurFtn(SwFmtFtn * pFillFtn)217cdf0e10cSrcweir sal_Bool SwEditShell::GetCurFtn( SwFmtFtn* pFillFtn )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir 	// der Cursor muss auf dem akt. Fussnoten-Anker stehen:
220cdf0e10cSrcweir 	SwPaM* pCrsr = GetCrsr();
221cdf0e10cSrcweir 	SwTxtNode* pTxtNd = pCrsr->GetNode()->GetTxtNode();
222cdf0e10cSrcweir 	if( !pTxtNd )
223cdf0e10cSrcweir 		return sal_False;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     SwTxtAttr *const pFtn = pTxtNd->GetTxtAttrForCharAt(
226cdf0e10cSrcweir         pCrsr->GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN);
227cdf0e10cSrcweir 	if( pFtn && pFillFtn )
228cdf0e10cSrcweir 	{
229cdf0e10cSrcweir 		// Daten vom Attribut uebertragen
230cdf0e10cSrcweir 		const SwFmtFtn &rFtn = ((SwTxtFtn*)pFtn)->GetFtn();
231cdf0e10cSrcweir 		pFillFtn->SetNumber( rFtn );
232cdf0e10cSrcweir 		pFillFtn->SetEndNote( rFtn.IsEndNote() );
233cdf0e10cSrcweir 	}
234cdf0e10cSrcweir 	return 0 != pFtn;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 
SetCurFtn(const SwFmtFtn & rFillFtn)238cdf0e10cSrcweir bool SwEditShell::SetCurFtn( const SwFmtFtn& rFillFtn )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir     bool bChgd = false;
241*69a74367SOliver-Rainer Wittmann     StartAllAction();
242cdf0e10cSrcweir 
243*69a74367SOliver-Rainer Wittmann     SwPaM* pCrsr = GetCrsr(), *pFirst = pCrsr;
244*69a74367SOliver-Rainer Wittmann     do {
245*69a74367SOliver-Rainer Wittmann         bChgd |=
246*69a74367SOliver-Rainer Wittmann             pDoc->SetCurFtn( *pCrsr, rFillFtn.GetNumStr(), rFillFtn.GetNumber(), rFillFtn.IsEndNote() );
247cdf0e10cSrcweir 
248*69a74367SOliver-Rainer Wittmann     } while( pFirst != ( pCrsr = (SwPaM*)pCrsr->GetNext() ));
249cdf0e10cSrcweir 
250*69a74367SOliver-Rainer Wittmann     EndAllAction();
251*69a74367SOliver-Rainer Wittmann     return bChgd;
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 
256cdf0e10cSrcweir /*sal_uInt16 SwEditShell::GetFtnCnt( sal_Bool bEndNotes = sal_False ) const
257cdf0e10cSrcweir {
258cdf0e10cSrcweir 	const SwFtnIdxs &rIdxs = pDoc->GetFtnIdxs();
259cdf0e10cSrcweir 	sal_uInt16 nCnt = 0;
260cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < rIdxs.Count(); ++i )
261cdf0e10cSrcweir 	{
262cdf0e10cSrcweir 		const SwFmtFtn &rFtn = rIdxs[i]->GetFtn();
263cdf0e10cSrcweir 		if ( bEndNotes == rFtn.IsEndNote() )
264cdf0e10cSrcweir 			nCnt++;
265cdf0e10cSrcweir 	}
266cdf0e10cSrcweir 	return nCnt;
267cdf0e10cSrcweir } */
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 
HasFtns(bool bEndNotes) const270cdf0e10cSrcweir bool SwEditShell::HasFtns( bool bEndNotes ) const
271cdf0e10cSrcweir {
272cdf0e10cSrcweir 	const SwFtnIdxs &rIdxs = pDoc->GetFtnIdxs();
273cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < rIdxs.Count(); ++i )
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir 		const SwFmtFtn &rFtn = rIdxs[i]->GetFtn();
276cdf0e10cSrcweir 		if ( bEndNotes == rFtn.IsEndNote() )
277cdf0e10cSrcweir 			return sal_True;
278cdf0e10cSrcweir 	}
279cdf0e10cSrcweir 	return sal_False;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 	// gebe Liste aller Fussnoten und deren Anfangstexte
GetSeqFtnList(SwSeqFldList & rList,bool bEndNotes)284cdf0e10cSrcweir sal_uInt16 SwEditShell::GetSeqFtnList( SwSeqFldList& rList, bool bEndNotes )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	if( rList.Count() )
287cdf0e10cSrcweir 		rList.Remove( 0, rList.Count() );
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	sal_uInt16 n, nFtnCnt = pDoc->GetFtnIdxs().Count();
290cdf0e10cSrcweir 	SwTxtFtn* pTxtFtn;
291cdf0e10cSrcweir 	for( n = 0; n < nFtnCnt; ++n )
292cdf0e10cSrcweir 	{
293cdf0e10cSrcweir 		pTxtFtn = pDoc->GetFtnIdxs()[ n ];
294cdf0e10cSrcweir 		const SwFmtFtn& rFtn = pTxtFtn->GetFtn();
295cdf0e10cSrcweir 		if ( rFtn.IsEndNote() != bEndNotes )
296cdf0e10cSrcweir 			continue;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 		SwNodeIndex* pIdx = pTxtFtn->GetStartNode();
299cdf0e10cSrcweir 		if( pIdx )
300cdf0e10cSrcweir 		{
301cdf0e10cSrcweir 			SwNodeIndex aIdx( *pIdx, 1 );
302cdf0e10cSrcweir 			SwTxtNode* pTxtNd = aIdx.GetNode().GetTxtNode();
303cdf0e10cSrcweir 			if( !pTxtNd )
304cdf0e10cSrcweir 				pTxtNd = (SwTxtNode*)pDoc->GetNodes().GoNext( &aIdx );
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 			if( pTxtNd )
307cdf0e10cSrcweir 			{
308cdf0e10cSrcweir 				String sTxt( rFtn.GetViewNumStr( *pDoc ));
309cdf0e10cSrcweir 				if( sTxt.Len() )
310cdf0e10cSrcweir 					sTxt += ' ';
311cdf0e10cSrcweir                 sTxt += pTxtNd->GetExpandTxt( 0, USHRT_MAX );
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 				_SeqFldLstElem* pNew = new _SeqFldLstElem( sTxt,
314cdf0e10cSrcweir 											pTxtFtn->GetSeqRefNo() );
315cdf0e10cSrcweir 				while( rList.InsertSort( pNew ) )
316cdf0e10cSrcweir 					pNew->sDlgEntry += ' ';
317cdf0e10cSrcweir 			}
318cdf0e10cSrcweir 		}
319cdf0e10cSrcweir 	}
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 	return rList.Count();
322cdf0e10cSrcweir }
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 
325cdf0e10cSrcweir // linken Rand ueber Objectleiste einstellen (aenhlich dem Stufen von
326cdf0e10cSrcweir // Numerierungen)
IsMoveLeftMargin(sal_Bool bRight,sal_Bool bModulus) const327cdf0e10cSrcweir sal_Bool SwEditShell::IsMoveLeftMargin( sal_Bool bRight, sal_Bool bModulus ) const
328cdf0e10cSrcweir {
329cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 	const SvxTabStopItem& rTabItem = (SvxTabStopItem&)GetDoc()->
332cdf0e10cSrcweir 								GetDefault( RES_PARATR_TABSTOP );
333cdf0e10cSrcweir 	sal_uInt16 nDefDist = static_cast<sal_uInt16>(rTabItem.Count() ? rTabItem[0].GetTabPos() : 1134);
334cdf0e10cSrcweir 	if( !nDefDist )
335cdf0e10cSrcweir 		return sal_False;
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 	FOREACHPAM_START(this)
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 		sal_uLong nSttNd = PCURCRSR->GetMark()->nNode.GetIndex(),
340cdf0e10cSrcweir 			  nEndNd = PCURCRSR->GetPoint()->nNode.GetIndex();
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 		if( nSttNd > nEndNd )
343cdf0e10cSrcweir 		{
344cdf0e10cSrcweir 			sal_uLong nTmp = nSttNd; nSttNd = nEndNd; nEndNd = nTmp;
345cdf0e10cSrcweir 		}
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 		SwCntntNode* pCNd;
348cdf0e10cSrcweir 		for( sal_uLong n = nSttNd; bRet && n <= nEndNd; ++n )
349cdf0e10cSrcweir 			if( 0 != ( pCNd = GetDoc()->GetNodes()[ n ]->GetTxtNode() ))
350cdf0e10cSrcweir 			{
351cdf0e10cSrcweir 				const SvxLRSpaceItem& rLS = (SvxLRSpaceItem&)
352cdf0e10cSrcweir 											pCNd->GetAttr( RES_LR_SPACE );
353cdf0e10cSrcweir 				if( bRight )
354cdf0e10cSrcweir 				{
355cdf0e10cSrcweir 					long nNext = rLS.GetTxtLeft() + nDefDist;
356cdf0e10cSrcweir 					if( bModulus )
357cdf0e10cSrcweir 						nNext = ( nNext / nDefDist ) * nDefDist;
358cdf0e10cSrcweir 					SwFrm* pFrm = pCNd->getLayoutFrm( GetLayout() );
359cdf0e10cSrcweir                     if ( pFrm )
360cdf0e10cSrcweir                     {
361cdf0e10cSrcweir                         const sal_uInt16 nFrmWidth = static_cast<sal_uInt16>( pFrm->IsVertical() ?
362cdf0e10cSrcweir                                                  pFrm->Frm().Height() :
363cdf0e10cSrcweir                                                  pFrm->Frm().Width() );
364cdf0e10cSrcweir                         bRet = nFrmWidth > ( nNext + MM50 );
365cdf0e10cSrcweir                     }
366cdf0e10cSrcweir                     else
367cdf0e10cSrcweir                         bRet = sal_False;
368cdf0e10cSrcweir 				}
369cdf0e10cSrcweir 			}
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 		if( !bRet )
372cdf0e10cSrcweir 			break;
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 	FOREACHPAM_END()
375cdf0e10cSrcweir 	return bRet;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
MoveLeftMargin(sal_Bool bRight,sal_Bool bModulus)378cdf0e10cSrcweir void SwEditShell::MoveLeftMargin( sal_Bool bRight, sal_Bool bModulus )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir 	StartAllAction();
381cdf0e10cSrcweir 	StartUndo( UNDO_START );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 	SwPaM* pCrsr = GetCrsr();
384cdf0e10cSrcweir 	if( pCrsr->GetNext() != pCrsr )			// Mehrfachselektion ?
385cdf0e10cSrcweir 	{
386cdf0e10cSrcweir 		SwPamRanges aRangeArr( *pCrsr );
387cdf0e10cSrcweir 		SwPaM aPam( *pCrsr->GetPoint() );
388cdf0e10cSrcweir 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
389cdf0e10cSrcweir 			GetDoc()->MoveLeftMargin( aRangeArr.SetPam( n, aPam ),
390cdf0e10cSrcweir 										bRight, bModulus );
391cdf0e10cSrcweir 	}
392cdf0e10cSrcweir 	else
393cdf0e10cSrcweir 		GetDoc()->MoveLeftMargin( *pCrsr, bRight, bModulus );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	EndUndo( UNDO_END );
396cdf0e10cSrcweir 	EndAllAction();
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 
lcl_SetScriptFlags(sal_uInt16 nType)400cdf0e10cSrcweir inline sal_uInt16 lcl_SetScriptFlags( sal_uInt16 nType )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir 	sal_uInt16 nRet;
403cdf0e10cSrcweir    	switch( nType )
404cdf0e10cSrcweir 	{
405cdf0e10cSrcweir 	case ::com::sun::star::i18n::ScriptType::LATIN:		nRet = SCRIPTTYPE_LATIN;	break;
406cdf0e10cSrcweir 	case ::com::sun::star::i18n::ScriptType::ASIAN:		nRet = SCRIPTTYPE_ASIAN;	break;
407cdf0e10cSrcweir 	case ::com::sun::star::i18n::ScriptType::COMPLEX:	nRet = SCRIPTTYPE_COMPLEX;	break;
408cdf0e10cSrcweir 	default: nRet = 0;
409cdf0e10cSrcweir 	}
410cdf0e10cSrcweir 	return nRet;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
lcl_IsNoEndTxtAttrAtPos(const SwTxtNode & rTNd,xub_StrLen nPos,sal_uInt16 & rScrpt,sal_Bool bInSelection,sal_Bool bNum)413cdf0e10cSrcweir sal_Bool lcl_IsNoEndTxtAttrAtPos( const SwTxtNode& rTNd, xub_StrLen nPos,
414cdf0e10cSrcweir                             sal_uInt16 &rScrpt, sal_Bool bInSelection, sal_Bool bNum )
415cdf0e10cSrcweir {
416cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
417cdf0e10cSrcweir 	const String& rTxt = rTNd.GetTxt();
418cdf0e10cSrcweir     String sExp;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir     // consider numbering
421cdf0e10cSrcweir     if ( bNum )
422cdf0e10cSrcweir     {
423cdf0e10cSrcweir         bRet = sal_False;
424cdf0e10cSrcweir 
425cdf0e10cSrcweir         if ( rTNd.IsInList() )
426cdf0e10cSrcweir         {
427cdf0e10cSrcweir             ASSERT( rTNd.GetNumRule(),
428cdf0e10cSrcweir                     "<lcl_IsNoEndTxtAttrAtPos(..)> - no list style found at text node. Serious defect -> please inform OD." );
429cdf0e10cSrcweir             const SwNumRule* pNumRule = rTNd.GetNumRule();
430*69a74367SOliver-Rainer Wittmann             //Modified for i119959,2012.6.12
431*69a74367SOliver-Rainer Wittmann             //Under this scenario,this pointer is null,but on win,it doesn't crash immediately
432*69a74367SOliver-Rainer Wittmann             //it exits with exception,and associated memory will have problem which leads to crash problem in
433*69a74367SOliver-Rainer Wittmann             //other place in dev env...
434*69a74367SOliver-Rainer Wittmann             if ( pNumRule )
435cdf0e10cSrcweir             {
436*69a74367SOliver-Rainer Wittmann                 //End
437*69a74367SOliver-Rainer Wittmann                 const SwNumFmt &rNumFmt = pNumRule->Get( static_cast<sal_uInt16>(rTNd.GetActualListLevel()) );
438*69a74367SOliver-Rainer Wittmann                 if( SVX_NUM_BITMAP != rNumFmt.GetNumberingType() )
439*69a74367SOliver-Rainer Wittmann                 {
440*69a74367SOliver-Rainer Wittmann                     if ( SVX_NUM_CHAR_SPECIAL == rNumFmt.GetNumberingType() )
441*69a74367SOliver-Rainer Wittmann                         sExp = rNumFmt.GetBulletChar();
442*69a74367SOliver-Rainer Wittmann                     else
443*69a74367SOliver-Rainer Wittmann                         sExp = rTNd.GetNumString();
444*69a74367SOliver-Rainer Wittmann                 }
445*69a74367SOliver-Rainer Wittmann                 //Modified for i119959,2012.6.12
446*69a74367SOliver-Rainer Wittmann                 //Under this scenario,this pointer is null,but on win,it doesn't crash immediately
447*69a74367SOliver-Rainer Wittmann                 //it exits with exception,and associated memory will have problem which leads to crash problem in
448*69a74367SOliver-Rainer Wittmann                 //other place in dev env...
449*69a74367SOliver-Rainer Wittmann             }
450*69a74367SOliver-Rainer Wittmann             //End
451cdf0e10cSrcweir         }
452cdf0e10cSrcweir     }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     // and fields
455cdf0e10cSrcweir     if ( CH_TXTATR_BREAKWORD == rTxt.GetChar( nPos ) )
456cdf0e10cSrcweir     {
457cdf0e10cSrcweir         const SwTxtAttr* const pAttr = rTNd.GetTxtAttrForCharAt( nPos );
458cdf0e10cSrcweir         if (pAttr)
459cdf0e10cSrcweir         {
460cdf0e10cSrcweir             bRet = sal_True; // all other than fields can be
461cdf0e10cSrcweir                          // defined as weak-script ?
462cdf0e10cSrcweir             if ( RES_TXTATR_FIELD == pAttr->Which() )
463cdf0e10cSrcweir             {
464c0286415SOliver-Rainer Wittmann                 const SwField* const pFld = pAttr->GetFmtFld().GetField();
465cdf0e10cSrcweir                 if (pFld)
466cdf0e10cSrcweir                 {
467cdf0e10cSrcweir                     sExp += pFld->ExpandField(true);
468cdf0e10cSrcweir                 }
469cdf0e10cSrcweir             }
470cdf0e10cSrcweir         }
471cdf0e10cSrcweir     }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     xub_StrLen nEnd = sExp.Len();
474cdf0e10cSrcweir     if ( nEnd )
475cdf0e10cSrcweir     {
476cdf0e10cSrcweir         xub_StrLen n;
477cdf0e10cSrcweir         if( bInSelection )
478cdf0e10cSrcweir         {
479cdf0e10cSrcweir             sal_uInt16 nScript;
480cdf0e10cSrcweir             for( n = 0; n < nEnd; n = (xub_StrLen)
481cdf0e10cSrcweir                     pBreakIt->GetBreakIter()->endOfScript( sExp, n, nScript ))
482cdf0e10cSrcweir             {
483cdf0e10cSrcweir                 nScript = pBreakIt->GetBreakIter()->getScriptType( sExp, n );
484cdf0e10cSrcweir                 rScrpt |= lcl_SetScriptFlags( nScript );
485cdf0e10cSrcweir             }
486cdf0e10cSrcweir         }
487cdf0e10cSrcweir         else
488cdf0e10cSrcweir             rScrpt |= lcl_SetScriptFlags( pBreakIt->GetBreakIter()->
489cdf0e10cSrcweir                                         getScriptType( sExp, nEnd-1 ));
490cdf0e10cSrcweir     }
491cdf0e10cSrcweir 
492*69a74367SOliver-Rainer Wittmann     return bRet;
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 
496cdf0e10cSrcweir // returns the scripttpye of the selection
GetScriptType() const497cdf0e10cSrcweir sal_uInt16 SwEditShell::GetScriptType() const
498cdf0e10cSrcweir {
499cdf0e10cSrcweir 	sal_uInt16 nRet = 0;
500cdf0e10cSrcweir 	//if( pBreakIt->GetBreakIter().is() )
501cdf0e10cSrcweir 	{
502cdf0e10cSrcweir 		FOREACHPAM_START(this)
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 			const SwPosition *pStt = PCURCRSR->Start(),
505cdf0e10cSrcweir 							 *pEnd = pStt == PCURCRSR->GetMark()
506cdf0e10cSrcweir 									? PCURCRSR->GetPoint()
507cdf0e10cSrcweir 									: PCURCRSR->GetMark();
508cdf0e10cSrcweir 			if( pStt == pEnd || *pStt == *pEnd )
509cdf0e10cSrcweir 			{
510cdf0e10cSrcweir 				const SwTxtNode* pTNd = pStt->nNode.GetNode().GetTxtNode();
511cdf0e10cSrcweir 				if( pTNd )
512cdf0e10cSrcweir 				{
513cdf0e10cSrcweir                     // try to get SwScriptInfo
514cdf0e10cSrcweir                     const SwScriptInfo* pScriptInfo = SwScriptInfo::GetScriptInfo( *pTNd );
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 					xub_StrLen nPos = pStt->nContent.GetIndex();
517cdf0e10cSrcweir 					//Task 90448: we need the scripttype of the previous
518cdf0e10cSrcweir 					//				position, if no selection exist!
519cdf0e10cSrcweir 					if( nPos )
520cdf0e10cSrcweir 					{
521cdf0e10cSrcweir 						SwIndex aIdx( pStt->nContent );
522cdf0e10cSrcweir 						if( pTNd->GoPrevious( &aIdx, CRSR_SKIP_CHARS ) )
523cdf0e10cSrcweir 							nPos = aIdx.GetIndex();
524cdf0e10cSrcweir 					}
525cdf0e10cSrcweir 
526cdf0e10cSrcweir                     sal_uInt16 nScript;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir                     if ( pTNd->GetTxt().Len() )
529cdf0e10cSrcweir                     {
530cdf0e10cSrcweir                         nScript = pScriptInfo ?
531cdf0e10cSrcweir                                   pScriptInfo->ScriptType( nPos ) :
532cdf0e10cSrcweir                                   pBreakIt->GetBreakIter()->getScriptType( pTNd->GetTxt(), nPos );
533cdf0e10cSrcweir                     }
534cdf0e10cSrcweir                     else
535cdf0e10cSrcweir                         nScript = GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() );
536cdf0e10cSrcweir 
537cdf0e10cSrcweir                     if( !lcl_IsNoEndTxtAttrAtPos( *pTNd, nPos, nRet, sal_False, sal_False ))
538cdf0e10cSrcweir                         nRet |= lcl_SetScriptFlags( nScript );
539cdf0e10cSrcweir 				}
540cdf0e10cSrcweir 			}
541cdf0e10cSrcweir 			else if ( pBreakIt->GetBreakIter().is() )
542cdf0e10cSrcweir 			{
543cdf0e10cSrcweir 				sal_uLong nEndIdx = pEnd->nNode.GetIndex();
544cdf0e10cSrcweir 				SwNodeIndex aIdx( pStt->nNode );
545cdf0e10cSrcweir 				for( ; aIdx.GetIndex() <= nEndIdx; aIdx++ )
546cdf0e10cSrcweir 					if( aIdx.GetNode().IsTxtNode() )
547cdf0e10cSrcweir 					{
548cdf0e10cSrcweir 						const SwTxtNode* pTNd = aIdx.GetNode().GetTxtNode();
549cdf0e10cSrcweir 						const String& rTxt = pTNd->GetTxt();
550cdf0e10cSrcweir 
551cdf0e10cSrcweir                         // try to get SwScriptInfo
552cdf0e10cSrcweir                         const SwScriptInfo* pScriptInfo = SwScriptInfo::GetScriptInfo( *pTNd );
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 						xub_StrLen nChg = aIdx == pStt->nNode
555cdf0e10cSrcweir 												? pStt->nContent.GetIndex()
556cdf0e10cSrcweir 												: 0,
557cdf0e10cSrcweir 									nEndPos = aIdx == nEndIdx
558cdf0e10cSrcweir 												? pEnd->nContent.GetIndex()
559cdf0e10cSrcweir                                                 : rTxt.Len();
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 						ASSERT( nEndPos <= rTxt.Len(), "Index outside the range - endless loop!" );
562cdf0e10cSrcweir 						if( nEndPos > rTxt.Len() )
563cdf0e10cSrcweir 							nEndPos = rTxt.Len();
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 						sal_uInt16 nScript;
566cdf0e10cSrcweir 						while( nChg < nEndPos )
567cdf0e10cSrcweir 						{
568cdf0e10cSrcweir                             nScript = pScriptInfo ?
569cdf0e10cSrcweir                                       pScriptInfo->ScriptType( nChg ) :
570cdf0e10cSrcweir                                       pBreakIt->GetBreakIter()->getScriptType(
571cdf0e10cSrcweir 																rTxt, nChg );
572cdf0e10cSrcweir 
573cdf0e10cSrcweir                             if( !lcl_IsNoEndTxtAttrAtPos( *pTNd, nChg, nRet, sal_True,
574cdf0e10cSrcweir                                                           0 == nChg && rTxt.Len() == nEndPos ) )
575cdf0e10cSrcweir 								nRet |= lcl_SetScriptFlags( nScript );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 							if( (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN |
578cdf0e10cSrcweir 								SCRIPTTYPE_COMPLEX) == nRet )
579cdf0e10cSrcweir 								break;
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 							xub_StrLen nFldPos = nChg+1;
582cdf0e10cSrcweir 
583cdf0e10cSrcweir                             nChg = pScriptInfo ?
584cdf0e10cSrcweir                                    pScriptInfo->NextScriptChg( nChg ) :
585cdf0e10cSrcweir                                    (xub_StrLen)pBreakIt->GetBreakIter()->endOfScript(
586cdf0e10cSrcweir 													rTxt, nChg, nScript );
587cdf0e10cSrcweir 
588cdf0e10cSrcweir                             nFldPos = rTxt.Search(
589cdf0e10cSrcweir 											CH_TXTATR_BREAKWORD, nFldPos );
590cdf0e10cSrcweir 							if( nFldPos < nChg )
591cdf0e10cSrcweir 								nChg = nFldPos;
592cdf0e10cSrcweir 						}
593cdf0e10cSrcweir 						if( (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN |
594cdf0e10cSrcweir 								SCRIPTTYPE_COMPLEX) == nRet )
595cdf0e10cSrcweir 							break;
596cdf0e10cSrcweir 					}
597cdf0e10cSrcweir 			}
598cdf0e10cSrcweir 			if( (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN |
599cdf0e10cSrcweir 								SCRIPTTYPE_COMPLEX) == nRet )
600cdf0e10cSrcweir 				break;
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 		FOREACHPAM_END()
603cdf0e10cSrcweir 	}
604cdf0e10cSrcweir 	if( !nRet )
605cdf0e10cSrcweir         nRet = SvtLanguageOptions::GetScriptTypeOfLanguage( LANGUAGE_SYSTEM );
606cdf0e10cSrcweir 	return nRet;
607cdf0e10cSrcweir }
608cdf0e10cSrcweir 
609cdf0e10cSrcweir 
GetCurLang() const610cdf0e10cSrcweir sal_uInt16 SwEditShell::GetCurLang() const
611cdf0e10cSrcweir {
612cdf0e10cSrcweir 	const SwPaM* pCrsr = GetCrsr();
613cdf0e10cSrcweir 	const SwPosition& rPos = *pCrsr->GetPoint();
614cdf0e10cSrcweir 	const SwTxtNode* pTNd = rPos.nNode.GetNode().GetTxtNode();
615cdf0e10cSrcweir 	sal_uInt16 nLang;
616cdf0e10cSrcweir 	if( pTNd )
617cdf0e10cSrcweir 	{
618cdf0e10cSrcweir 		//JP 24.9.2001: if exist no selection, then get the language before
619cdf0e10cSrcweir 		//				the current character!
620cdf0e10cSrcweir 		xub_StrLen nPos = rPos.nContent.GetIndex();
621cdf0e10cSrcweir 		if( nPos && !pCrsr->HasMark() )
622cdf0e10cSrcweir 			--nPos;
623cdf0e10cSrcweir 		nLang = pTNd->GetLang( nPos );
624cdf0e10cSrcweir 	}
625cdf0e10cSrcweir 	else
626cdf0e10cSrcweir 		nLang = LANGUAGE_DONTKNOW;
627cdf0e10cSrcweir 	return nLang;
628cdf0e10cSrcweir }
629cdf0e10cSrcweir 
GetScalingOfSelectedText() const630cdf0e10cSrcweir sal_uInt16 SwEditShell::GetScalingOfSelectedText() const
631cdf0e10cSrcweir {
632cdf0e10cSrcweir 	const SwPaM* pCrsr = GetCrsr();
633cdf0e10cSrcweir 	const SwPosition* pStt = pCrsr->Start();
634cdf0e10cSrcweir 	const SwTxtNode* pTNd = pStt->nNode.GetNode().GetTxtNode();
635cdf0e10cSrcweir 	ASSERT( pTNd, "no textnode available" );
636cdf0e10cSrcweir 
637cdf0e10cSrcweir 	sal_uInt16 nScaleWidth;
638cdf0e10cSrcweir 	if( pTNd )
639cdf0e10cSrcweir 	{
640cdf0e10cSrcweir 		xub_StrLen nStt = pStt->nContent.GetIndex(), nEnd;
641cdf0e10cSrcweir 		const SwPosition* pEnd = pStt == pCrsr->GetPoint()
642cdf0e10cSrcweir 										? pCrsr->GetMark()
643cdf0e10cSrcweir 										: pCrsr->GetPoint();
644cdf0e10cSrcweir 		if( pStt->nNode == pEnd->nNode )
645cdf0e10cSrcweir 			nEnd = pEnd->nContent.GetIndex();
646cdf0e10cSrcweir 		else
647cdf0e10cSrcweir 			nEnd = pTNd->GetTxt().Len();
648cdf0e10cSrcweir 		nScaleWidth = pTNd->GetScalingOfSelectedText( nStt, nEnd );
649cdf0e10cSrcweir 	}
650cdf0e10cSrcweir 	else
651cdf0e10cSrcweir 		nScaleWidth = 100;		        // default are no scaling -> 100%
652cdf0e10cSrcweir 	return nScaleWidth;
653cdf0e10cSrcweir }
654