1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <swacorr.hxx>
21 #include <swblocks.hxx>
22 #include <SwXMLTextBlocks.hxx>
23 #include <docsh.hxx>
24 #include <editsh.hxx>
25 #include <osl/diagnose.h>
26
27 using namespace ::com::sun::star;
28
29 /**
30 * Returns the replacement text
31 *
32 * Only for the SWG format, all others can be extracted from the word list
33 *
34 * @param rShort - the stream name (encrypted)
35 */
GetLongText(const OUString & rShort,OUString & rLong)36 bool SwAutoCorrect::GetLongText( const OUString& rShort, OUString& rLong )
37 {
38 ErrCode nRet = ERRCODE_NONE;
39 assert( m_pTextBlocks );
40 nRet = m_pTextBlocks->GetText( rShort, rLong );
41 return !nRet.IsError() && !rLong.isEmpty();
42 }
43
refreshBlockList(const uno::Reference<embed::XStorage> & rStg)44 void SwAutoCorrect::refreshBlockList( const uno::Reference< embed::XStorage >& rStg )
45 {
46 if (rStg.is())
47 {
48 // mba: relative URLs don't make sense here
49 m_pTextBlocks.reset( new SwXMLTextBlocks( rStg, OUString() ) );
50 }
51 else {
52 OSL_ENSURE( rStg.is(), "Someone passed SwAutoCorrect::refreshBlockList a dud storage!");
53 }
54 }
55
56 /**
57 * Text with attributes
58 *
59 * Only for SWG format
60 *
61 * @param rShort - the stream name (encrypted)
62 */
PutText(const uno::Reference<embed::XStorage> & rStg,const OUString & rFileName,const OUString & rShort,SfxObjectShell & rObjSh,OUString & rLong)63 bool SwAutoCorrect::PutText( const uno::Reference < embed::XStorage >& rStg,
64 const OUString& rFileName, const OUString& rShort,
65 SfxObjectShell& rObjSh, OUString& rLong )
66 {
67 SwDocShell* pDShell = dynamic_cast<SwDocShell*>(&rObjSh);
68 if( !pDShell )
69 return false;
70
71 ErrCode nRet = ERRCODE_NONE;
72
73 // mba: relative URLs don't make sense here
74 SwXMLTextBlocks aBlk( rStg, rFileName );
75 SwDoc* pDoc = aBlk.GetDoc();
76
77 nRet = aBlk.BeginPutDoc( rShort, rShort );
78 if( ! nRet.IsError() )
79 {
80 pDShell->GetEditShell()->CopySelToDoc( *pDoc );
81 nRet = aBlk.PutDoc();
82 aBlk.AddName ( rShort, rShort );
83 if( ! nRet.IsError() )
84 nRet = aBlk.GetText( rShort, rLong );
85 }
86 return ! nRet.IsError();
87 }
88
SwAutoCorrect(const SvxAutoCorrect & rACorr)89 SwAutoCorrect::SwAutoCorrect( const SvxAutoCorrect& rACorr )
90 : SvxAutoCorrect( rACorr )
91 {
92 SwEditShell::SetAutoFormatFlags(&GetSwFlags());
93 }
94
~SwAutoCorrect()95 SwAutoCorrect::~SwAutoCorrect()
96 {
97 }
98
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
100