LibreOffice Module sw (master)  1
swacorr.cxx
Go to the documentation of this file.
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 
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 
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 
63 bool SwAutoCorrect::PutText( const uno::Reference < embed::XStorage >& rStg,
64  const OUString& rFileName, const OUString& rShort,
65  SfxObjectShell& rObjSh, OUString& rLong )
66 {
67  if( nullptr == dynamic_cast<const SwDocShell*>( &rObjSh) )
68  return false;
69 
70  SwDocShell& rDShell = static_cast<SwDocShell&>(rObjSh);
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  rDShell.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 
90  : SvxAutoCorrect( rACorr )
91 {
93 }
94 
96 {
97 }
98 
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool CopySelToDoc(SwDoc *pInsDoc)
For copying via ClipBoard: If table is copied into table, move all cursors away from it...
Definition: edglss.cxx:153
virtual void refreshBlockList(const css::uno::Reference< css::embed::XStorage > &) override
Definition: swacorr.cxx:44
Definition: doc.hxx:186
std::unique_ptr< SwXMLTextBlocks > m_pTextBlocks
Definition: swacorr.hxx:36
SwAutoCorrect(const SvxAutoCorrect &rACorr)
Definition: swacorr.cxx:89
SwEditShell * GetEditShell()
Definition: docsh.cxx:1203
virtual bool PutText(const css::uno::Reference< css::embed::XStorage > &, const OUString &rFileName, const OUString &rShort, SfxObjectShell &, OUString &) override
Text with attributes.
Definition: swacorr.cxx:63
SvxSwAutoFormatFlags & GetSwFlags()
virtual bool GetLongText(const OUString &rShort, OUString &rLong) override
Returns the replacement text.
Definition: swacorr.cxx:36
virtual ~SwAutoCorrect() override
Definition: swacorr.cxx:95
virtual ErrCode PutDoc() override
void AddName(const OUString &, const OUString &, const OUString &, bool bOnlyText)
bool IsError() const
#define ERRCODE_NONE
virtual ErrCode GetDoc(sal_uInt16) override
virtual ErrCode BeginPutDoc(const OUString &, const OUString &) override
static void SetAutoFormatFlags(SvxSwAutoFormatFlags const *)
Definition: autofmt.cxx:2784
ErrCode GetText(const OUString &rShort, OUString &)