1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: edglss.cxx,v $
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"
35 #include <osl/endian.h>
36 #include <hintids.hxx>
37 #include <svtools/urihelper.hxx>
38 #include <tools/cachestr.hxx>
45 #include <swundo.hxx> // fuer die UndoIds
47 #include <swtable.hxx> // fuers kopieren von Tabellen
48 #include <shellio.hxx> // SwTextBlocks
49 #include <acorrect.hxx>
50 #include <swerror.h> // SwTextBlocks
52 /******************************************************************************
53 * jetzt mit einem verkappten Reader/Writer/Dokument
54 ******************************************************************************/
56 void SwEditShell::InsertGlossary( SwTextBlocks
& rGlossary
, const String
& rStr
)
59 GetDoc()->InsertGlossary( rGlossary
, rStr
, *GetCrsr(), this );
64 /******************************************************************************
65 * aktuelle Selektion zum Textbaustein machen und ins
66 * Textbausteindokument einfuegen, einschliesslich Vorlagen
67 ******************************************************************************/
70 USHORT
SwEditShell::MakeGlossary( SwTextBlocks
& rBlks
, const String
& rName
, const String
& rShortName
,
71 BOOL bSaveRelFile
, const String
* pOnlyTxt
)
73 SwDoc
* pGDoc
= rBlks
.GetDoc();
78 INetURLObject
aURL( rBlks
.GetFileName() );
79 sBase
= aURL
.GetMainURL( INetURLObject::NO_DECODE
);
81 rBlks
.SetBaseURL( sBase
);
86 nRet
= rBlks
.PutText( rShortName
, rName
, *pOnlyTxt
);
90 if( rBlks
.BeginPutDoc( rShortName
, rName
) )
92 rBlks
.GetDoc()->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_DELETE_REDLINES
);
93 _CopySelToDoc( pGDoc
);
94 rBlks
.GetDoc()->SetRedlineMode_intern( (RedlineMode_t
)0 );
95 nRet
= rBlks
.PutDoc();
104 USHORT
SwEditShell::SaveGlossaryDoc( SwTextBlocks
& rBlock
,
106 const String
& rShortName
,
112 SwDoc
* pGDoc
= rBlock
.GetDoc();
113 SwDoc
* pMyDoc
= GetDoc();
118 INetURLObject
aURL( rBlock
.GetFileName() );
119 sBase
= aURL
.GetMainURL( INetURLObject::NO_DECODE
);
121 rBlock
.SetBaseURL( sBase
);
122 USHORT nRet
= USHRT_MAX
;
128 SwPaM
* pCrsr
= GetCrsr();
130 SwNodeIndex
aStt( pMyDoc
->GetNodes().GetEndOfExtras(), 1 );
131 SwCntntNode
* pCntntNd
= pMyDoc
->GetNodes().GoNext( &aStt
);
132 const SwNode
* pNd
= pCntntNd
->FindTableNode();
136 pCrsr
->GetPoint()->nNode
= *pNd
;
137 if( pNd
== pCntntNd
)
138 pCrsr
->GetPoint()->nContent
.Assign( pCntntNd
, 0 );
141 // dann bis zum Ende vom Nodes Array
142 pCrsr
->GetPoint()->nNode
= pMyDoc
->GetNodes().GetEndOfContent().GetIndex()-1;
143 pCntntNd
= pCrsr
->GetCntntNode();
145 pCrsr
->GetPoint()->nContent
.Assign( pCntntNd
, pCntntNd
->Len() );
148 if( GetSelectedText( sBuf
, GETSELTXT_PARABRK_TO_ONLYCR
) && sBuf
.Len() )
149 nRet
= rBlock
.PutText( rShortName
, rName
, sBuf
);
154 if( rBlock
.BeginPutDoc( rShortName
, rName
) )
156 SwNodeIndex
aStt( pMyDoc
->GetNodes().GetEndOfExtras(), 1 );
157 SwCntntNode
* pCntntNd
= pMyDoc
->GetNodes().GoNext( &aStt
);
158 const SwNode
* pNd
= pCntntNd
->FindTableNode();
159 if( !pNd
) pNd
= pCntntNd
;
160 SwPaM
aCpyPam( *pNd
);
163 // dann bis zum Ende vom Nodes Array
164 aCpyPam
.GetPoint()->nNode
= pMyDoc
->GetNodes().GetEndOfContent().GetIndex()-1;
165 pCntntNd
= aCpyPam
.GetCntntNode();
166 aCpyPam
.GetPoint()->nContent
.Assign( pCntntNd
, pCntntNd
->Len() );
168 aStt
= pGDoc
->GetNodes().GetEndOfExtras();
169 pCntntNd
= pGDoc
->GetNodes().GoNext( &aStt
);
170 SwPosition
aInsPos( aStt
, SwIndex( pCntntNd
));
171 pMyDoc
->CopyRange( aCpyPam
, aInsPos
, false );
173 nRet
= rBlock
.PutDoc();
180 /******************************************************************************
181 * kopiere alle Selectionen und das Doc
182 ******************************************************************************/
185 BOOL
SwEditShell::_CopySelToDoc( SwDoc
* pInsDoc
, SwNodeIndex
* pSttNd
)
187 ASSERT( pInsDoc
, "kein Ins.Dokument" );
189 SwNodes
& rNds
= pInsDoc
->GetNodes();
191 SwNodeIndex
aIdx( rNds
.GetEndOfContent(), -1 );
192 SwCntntNode
* pNd
= aIdx
.GetNode().GetCntntNode();
193 SwPosition
aPos( aIdx
, SwIndex( pNd
, pNd
->Len() ));
195 // soll der Index auf Anfang returnt werden ?
198 *pSttNd
= aPos
.nNode
;
203 SET_CURR_SHELL( this );
205 pInsDoc
->LockExpFlds();
209 // kopiere Teile aus einer Tabelle: lege eine Tabelle mit der Breite
210 // von der Originalen an und kopiere die selectierten Boxen.
211 // Die Groessen werden prozentual korrigiert.
213 // lasse ueber das Layout die Boxen suchen
216 GetTblSel( *this, aBoxes
);
217 if( aBoxes
.Count() && 0 != (pTblNd
= (SwTableNode
*)aBoxes
[0]
218 ->GetSttNd()->FindTableNode() ))
220 // teste ob der TabellenName kopiert werden kann
221 BOOL bCpyTblNm
= aBoxes
.Count() == pTblNd
->GetTable().GetTabSortBoxes().Count();
224 const String
& rTblName
= pTblNd
->GetTable().GetFrmFmt()->GetName();
225 const SwFrmFmts
& rTblFmts
= *pInsDoc
->GetTblFrmFmts();
226 for( USHORT n
= rTblFmts
.Count(); n
; )
227 if( rTblFmts
[ --n
]->GetName() == rTblName
)
233 bRet
= pInsDoc
->InsCopyOfTbl( aPos
, aBoxes
, 0, bCpyTblNm
, FALSE
);
240 bool bColSel
= _GetCrsr()->IsColumnSelection();
241 if( bColSel
&& pInsDoc
->IsClipBoard() )
242 pInsDoc
->SetColumnSelection( true );
244 FOREACHPAM_START(this)
246 if( !PCURCRSR
->HasMark() )
248 if( 0 != (pNd
= PCURCRSR
->GetCntntNode()) &&
249 ( bColSel
|| !pNd
->GetTxtNode() ) )
252 PCURCRSR
->Move( fnMoveForward
, fnGoCntnt
);
253 bRet
= GetDoc()->CopyRange( *PCURCRSR
, aPos
, false )
255 PCURCRSR
->Exchange();
256 PCURCRSR
->DeleteMark();
261 bRet
= GetDoc()->CopyRange( *PCURCRSR
, aPos
, false ) || bRet
;
268 pInsDoc
->UnlockExpFlds();
269 if( !pInsDoc
->IsExpFldsLocked() )
270 pInsDoc
->UpdateExpFlds(NULL
, true);
272 // die gemerkte Node-Position wieder auf den richtigen Node
280 /*------------------------------------------------------------------------
281 Beschreibung: Text innerhalb der Selektion erfragen
282 Returnwert: liefert FALSE, wenn der selektierte Bereich
283 zu gross ist, um in den Stringpuffer kopiert zu werden.
284 ------------------------------------------------------------------------*/
286 BOOL
SwEditShell::GetSelectedText( String
&rBuf
, int nHndlParaBrk
)
289 GetCrsr(); // ggfs. alle Cursor erzeugen lassen
293 if( GETSELTXT_PARABRK_TO_BLANK
== nHndlParaBrk
)
296 while( STRING_NOTFOUND
!=
297 ( nPos
= rBuf
.SearchAndReplace( 0x0a, ' ', nPos
)) )
300 else if( IsSelFullPara() &&
301 GETSELTXT_PARABRK_TO_ONLYCR
!= nHndlParaBrk
)
306 rBuf
+= String::CreateFromAscii(
307 RTL_CONSTASCII_STRINGPARAM( "\015\012" ));
312 else if( IsSelection() )
314 SvCacheStream
aStream(20480);
316 aStream
.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN
);
318 aStream
.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN
);
321 SwReaderWriter::GetWriter( String::CreateFromAscii( FILTER_TEXT
), String(), xWrt
);
324 // Selektierte Bereiche in ein ASCII Dokument schreiben
325 SwWriter
aWriter( aStream
, *this);
326 xWrt
->SetShowProgress( FALSE
);
328 switch( nHndlParaBrk
)
330 case GETSELTXT_PARABRK_TO_BLANK
:
331 xWrt
->bASCII_ParaAsBlanc
= TRUE
;
332 xWrt
->bASCII_NoLastLineEnd
= TRUE
;
335 case GETSELTXT_PARABRK_TO_ONLYCR
:
336 xWrt
->bASCII_ParaAsCR
= TRUE
;
337 xWrt
->bASCII_NoLastLineEnd
= TRUE
;
341 //JP 09.05.00: write as UNICODE ! (and not as ANSI)
342 SwAsciiOptions
aAsciiOpt( xWrt
->GetAsciiOptions() );
343 aAsciiOpt
.SetCharSet( RTL_TEXTENCODING_UCS2
);
344 xWrt
->SetAsciiOptions( aAsciiOpt
);
345 xWrt
->bUCS2_WithStartChar
= FALSE
;
348 if( !IsError( aWriter
.Write( xWrt
) ) &&
349 STRING_MAXLEN
> (( lLen
= aStream
.GetSize() )
350 / sizeof( sal_Unicode
)) + 1 )
352 aStream
<< (sal_Unicode
)'\0';
354 const sal_Unicode
*p
= (sal_Unicode
*)aStream
.GetBuffer();
359 sal_Unicode
* pStrBuf
= rBuf
.AllocBuffer( xub_StrLen(
360 ( lLen
/ sizeof( sal_Unicode
))) );
362 aStream
.ResetError();
363 aStream
.Read( pStrBuf
, lLen
);
364 pStrBuf
[ lLen
/ sizeof( sal_Unicode
) ] = '\0';