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
27using namespace ::com::sun::star;
28
36bool 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
44void 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
63bool 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
90 : SvxAutoCorrect( rACorr )
91{
93}
94
96{
97}
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsError() const
SvxSwAutoFormatFlags & GetSwFlags()
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
virtual void refreshBlockList(const css::uno::Reference< css::embed::XStorage > &) override
Definition: swacorr.cxx:44
SwAutoCorrect(const SvxAutoCorrect &rACorr)
Definition: swacorr.cxx:89
virtual ~SwAutoCorrect() override
Definition: swacorr.cxx:95
std::unique_ptr< SwXMLTextBlocks > m_pTextBlocks
Definition: swacorr.hxx:36
virtual bool GetLongText(const OUString &rShort, OUString &rLong) override
Returns the replacement text.
Definition: swacorr.cxx:36
SwEditShell * GetEditShell()
Definition: docsh.cxx:1220
Definition: doc.hxx:194
bool CopySelToDoc(SwDoc &rInsDoc)
For copying via ClipBoard: If table is copied into table, move all cursors away from it.
Definition: edglss.cxx:152
static void SetAutoFormatFlags(SvxSwAutoFormatFlags const *)
Definition: autofmt.cxx:2801
virtual ErrCode GetDoc(sal_uInt16) override
virtual ErrCode PutDoc() override
ErrCode GetText(std::u16string_view rShort, OUString &)
void AddName(const OUString &, const OUString &, const OUString &, bool bOnlyText)
virtual ErrCode BeginPutDoc(const OUString &, const OUString &) override
#define ERRCODE_NONE