1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <swacorr.hxx>
21 #include <swblocks.hxx>
22 #include <SwXMLTextBlocks.hxx>
25 #include <osl/diagnose.h>
27 using namespace ::com::sun::star
;
30 * Returns the replacement text
32 * Only for the SWG format, all others can be extracted from the word list
34 * @param rShort - the stream name (encrypted)
36 bool SwAutoCorrect::GetLongText( const OUString
& rShort
, OUString
& rLong
)
38 ErrCode nRet
= ERRCODE_NONE
;
39 assert( m_pTextBlocks
);
40 nRet
= m_pTextBlocks
->GetText( rShort
, rLong
);
41 return !nRet
.IsError() && !rLong
.isEmpty();
44 void SwAutoCorrect::refreshBlockList( const uno::Reference
< embed::XStorage
>& rStg
)
48 // mba: relative URLs don't make sense here
49 m_pTextBlocks
.reset( new SwXMLTextBlocks( rStg
, OUString() ) );
52 OSL_ENSURE( rStg
.is(), "Someone passed SwAutoCorrect::refreshBlockList a dud storage!");
57 * Text with attributes
61 * @param rShort - the stream name (encrypted)
63 bool SwAutoCorrect::PutText( const uno::Reference
< embed::XStorage
>& rStg
,
64 const OUString
& rFileName
, const OUString
& rShort
,
65 SfxObjectShell
& rObjSh
, OUString
& rLong
)
67 SwDocShell
* pDShell
= dynamic_cast<SwDocShell
*>(&rObjSh
);
71 SwEditShell
* pEditSh
= pDShell
->GetEditShell();
75 ErrCode nRet
= ERRCODE_NONE
;
77 // mba: relative URLs don't make sense here
78 SwXMLTextBlocks
aBlk( rStg
, rFileName
);
79 SwDoc
* pDoc
= aBlk
.GetDoc();
81 nRet
= aBlk
.BeginPutDoc( rShort
, rShort
);
82 if( ! nRet
.IsError() )
84 pEditSh
->CopySelToDoc(*pDoc
);
86 aBlk
.AddName ( rShort
, rShort
);
87 if( ! nRet
.IsError() )
88 nRet
= aBlk
.GetText( rShort
, rLong
);
90 return ! nRet
.IsError();
93 SwAutoCorrect::SwAutoCorrect( const SvxAutoCorrect
& rACorr
)
94 : SvxAutoCorrect( rACorr
)
96 SwEditShell::SetAutoFormatFlags(&GetSwFlags());
99 SwAutoCorrect::~SwAutoCorrect()
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */