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 SwEditShell* pEditSh = pDShell->GetEditShell();
72 if (!pEditSh)
73 return false;
74
75 ErrCode nRet = ERRCODE_NONE;
76
77 // mba: relative URLs don't make sense here
78 SwXMLTextBlocks aBlk( rStg, rFileName );
79 SwDoc* pDoc = aBlk.GetDoc();
80
81 nRet = aBlk.BeginPutDoc( rShort, rShort );
82 if( ! nRet.IsError() )
83 {
84 pEditSh->CopySelToDoc(*pDoc);
85 nRet = aBlk.PutDoc();
86 aBlk.AddName ( rShort, rShort );
87 if( ! nRet.IsError() )
88 nRet = aBlk.GetText( rShort, rLong );
89 }
90 return ! nRet.IsError();
91}
92
94 : SvxAutoCorrect( rACorr )
95{
97}
98
100{
101}
102
103/* 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:93
virtual ~SwAutoCorrect() override
Definition: swacorr.cxx:99
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:1218
Definition: doc.hxx:197
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:2821
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