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 <swerror.h>
24 #include <docsh.hxx>
25 #include <editsh.hxx>
26 #include <sot/storage.hxx>
27 #include <osl/diagnose.h>
28 
29 using namespace ::com::sun::star;
30 
38 bool SwAutoCorrect::GetLongText( const OUString& rShort, OUString& rLong )
39 {
40  ErrCode nRet = ERRCODE_NONE;
41  assert( m_pTextBlocks );
42  nRet = m_pTextBlocks->GetText( rShort, rLong );
43  return !nRet.IsError() && !rLong.isEmpty();
44 }
45 
46 void SwAutoCorrect::refreshBlockList( const uno::Reference< embed::XStorage >& rStg )
47 {
48  if (rStg.is())
49  {
50  // mba: relative URLs don't make sense here
51  m_pTextBlocks.reset( new SwXMLTextBlocks( rStg, OUString() ) );
52  }
53  else {
54  OSL_ENSURE( rStg.is(), "Someone passed SwAutoCorrect::refreshBlockList a dud storage!");
55  }
56 }
57 
65 bool SwAutoCorrect::PutText( const uno::Reference < embed::XStorage >& rStg,
66  const OUString& rFileName, const OUString& rShort,
67  SfxObjectShell& rObjSh, OUString& rLong )
68 {
69  if( nullptr == dynamic_cast<const SwDocShell*>( &rObjSh) )
70  return false;
71 
72  SwDocShell& rDShell = static_cast<SwDocShell&>(rObjSh);
73  ErrCode nRet = ERRCODE_NONE;
74 
75  // mba: relative URLs don't make sense here
76  SwXMLTextBlocks aBlk( rStg, rFileName );
77  SwDoc* pDoc = aBlk.GetDoc();
78 
79  nRet = aBlk.BeginPutDoc( rShort, rShort );
80  if( ! nRet.IsError() )
81  {
82  rDShell.GetEditShell()->CopySelToDoc( pDoc );
83  nRet = aBlk.PutDoc();
84  aBlk.AddName ( rShort, rShort );
85  if( ! nRet.IsError() )
86  nRet = aBlk.GetText( rShort, rLong );
87  }
88  return ! nRet.IsError();
89 }
90 
92  : SvxAutoCorrect( rACorr )
93 {
95 }
96 
98 {
99 }
100 
101 /* 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:150
virtual void refreshBlockList(const css::uno::Reference< css::embed::XStorage > &) override
Definition: swacorr.cxx:46
Definition: doc.hxx:185
std::unique_ptr< SwXMLTextBlocks > m_pTextBlocks
Definition: swacorr.hxx:36
SwAutoCorrect(const SvxAutoCorrect &rACorr)
Definition: swacorr.cxx:91
SwEditShell * GetEditShell()
Definition: docsh.cxx:1245
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:65
SvxSwAutoFormatFlags & GetSwFlags()
virtual bool GetLongText(const OUString &rShort, OUString &rLong) override
Returns the replacement text.
Definition: swacorr.cxx:38
virtual ~SwAutoCorrect() override
Definition: swacorr.cxx:97
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 &)