LibreOffice Module editeng (master) 1
overflowingtxt.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 <rtl/ustring.hxx>
21#include <sal/log.hxx>
22
24#include <editeng/outliner.hxx>
25#include <editeng/outlobj.hxx>
26#include <editeng/editeng.hxx>
27#include <editeng/editobj.hxx>
28#include <editeng/editdata.hxx>
29
30#include <editdoc.hxx>
31#include <utility>
32
33
35 css::uno::Reference< css::datatransfer::XTransferable > const & xOverflowingContent,
36 Outliner *pOutl,
37 OutlinerParaObject const *pNextPObj)
38{
39 if (!pNextPObj) {
40 pOutl->SetToEmptyText();
41 } else {
42 pOutl->SetText(*pNextPObj);
43 }
44
45 // Special case: if only empty text remove it at the end
46 bool bOnlyOneEmptyPara = !pNextPObj ||
47 (pOutl->GetParagraphCount() == 1 &&
48 pNextPObj->GetTextObject().GetText(0).isEmpty());
49
50 EditEngine &rEditEngine = const_cast<EditEngine &>(pOutl->GetEditEngine());
51
52 // XXX: this code should be moved in Outliner directly
53 // creating Outliner::InsertText(...transferable...)
54 EditSelection aStartSel(rEditEngine.CreateSelection(ESelection(0,0)));
55 EditSelection aNewSel = rEditEngine.InsertText(xOverflowingContent,
56 OUString(),
57 aStartSel.Min(),
58 true);
59
60 if (!bOnlyOneEmptyPara) {
61 // Separate Paragraphs
62 rEditEngine.InsertParaBreak(aNewSel);
63 }
64
65
66 return pOutl->CreateParaObject();
67}
68
70 css::uno::Reference< css::datatransfer::XTransferable > const & xOverflowingContent,
71 Outliner *pOutl,
72 OutlinerParaObject const *pNextPObj)
73{
74 if (!pNextPObj) {
75 pOutl->SetToEmptyText();
76 } else {
77 pOutl->SetText(*pNextPObj);
78 }
79
80 EditEngine &rEditEngine = const_cast<EditEngine &>(pOutl->GetEditEngine());
81
82 // XXX: this code should be moved in Outliner directly
83 // creating Outliner::InsertText(...transferable...)
84 EditSelection aStartSel(rEditEngine.CreateSelection(ESelection(0,0)));
85 // We don't need to mark the selection
86 // EditSelection aNewSel =
87 rEditEngine.InsertText(xOverflowingContent,
88 OUString(),
89 aStartSel.Min(),
90 true);
91
92 return pOutl->CreateParaObject();
93}
94
95css::uno::Reference< css::datatransfer::XTransferable > TextChainingUtils::CreateTransferableFromText(Outliner const *pOutl)
96{
97 const EditEngine &rEditEngine = pOutl->GetEditEngine();
98 sal_Int32 nLastPara = pOutl->GetParagraphCount()-1;
99 ESelection aWholeTextSel(0, 0, nLastPara, rEditEngine.GetTextLen(nLastPara));
100
101 return rEditEngine.CreateTransferable(aWholeTextSel);
102}
103
104
105
106OverflowingText::OverflowingText(css::uno::Reference< css::datatransfer::XTransferable > xOverflowingContent) :
107 mxOverflowingContent(std::move(xOverflowingContent))
108{
109
110}
111
112
113
114NonOverflowingText::NonOverflowingText(const ESelection &aSel, bool bLastParaInterrupted)
115 : maContentSel(aSel)
116 , mbLastParaInterrupted(bLastParaInterrupted)
117{
118}
119
121{
123}
124
125
127{
128 pOutliner->QuickDelete(maContentSel);
129 SAL_INFO("editeng.chaining", "Deleting selection from (Para: " << maContentSel.nStartPara
130 << ", Pos: " << maContentSel.nStartPos << ") to (Para: " << maContentSel.nEndPara
131 << ", Pos: " << maContentSel.nEndPos << ")");
132 return pOutliner->CreateParaObject();
133}
134
136{
137 //return getLastPositionSel(mpContentTextObj);
138
139 // return the starting point of the selection we are removing
141}
142
143// The equivalent of ToParaObject for OverflowingText. Here we are prepending the overflowing text to the old dest box's text
144// XXX: In a sense a better name for OverflowingText and NonOverflowingText are respectively DestLinkText and SourceLinkText
146{
148}
149
151{
153}
154
155
156OFlowChainedText::OFlowChainedText(Outliner const *pOutl, bool bIsDeepMerge)
157{
160
161 mbIsDeepMerge = bIsDeepMerge;
162}
163
165{
166}
167
168
170{
171 return mpNonOverflowingTxt->GetOverflowPointSel();
172}
173
175{
176 // Just return the roughly merged paras for now
177 if (!mpOverflowingTxt)
178 return std::nullopt;
179
180 if (mbIsDeepMerge) {
181 SAL_INFO("editeng.chaining", "[TEXTCHAINFLOW - OF] Deep merging paras" );
182 return mpOverflowingTxt->DeeplyMergeParaObject(pOutliner, pTextToBeMerged );
183 } else {
184 SAL_INFO("editeng.chaining", "[TEXTCHAINFLOW - OF] Juxtaposing paras" );
185 return mpOverflowingTxt->JuxtaposeParaObject(pOutliner, pTextToBeMerged );
186 }
187}
188
189
191{
193 return std::nullopt;
194
195 return mpNonOverflowingTxt->RemoveOverflowingText(pOutliner);
196}
197
199{
200 return mpNonOverflowingTxt->IsLastParaInterrupted();
201}
202
203
204
205UFlowChainedText::UFlowChainedText(Outliner const *pOutl, bool bIsDeepMerge)
206{
208 mbIsDeepMerge = bIsDeepMerge;
209}
210
212{
214
215 if (mbIsDeepMerge) {
216 SAL_INFO("editeng.chaining", "[TEXTCHAINFLOW - UF] Deep merging paras" );
217 pNewText = TextChainingUtils::DeeplyMergeParaObject(mxUnderflowingTxt, pOutl, pNextLinkWholeText);
218 } else {
219 // NewTextForCurBox = Txt(CurBox) ++ Txt(NextBox)
220 SAL_INFO("editeng.chaining", "[TEXTCHAINFLOW - UF] Juxtaposing paras" );
221 pNewText = TextChainingUtils::JuxtaposeParaObject(mxUnderflowingTxt, pOutl, pNextLinkWholeText);
222 }
223
224 return pNewText;
225
226}
227/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
EDITENG_DLLPRIVATE css::uno::Reference< css::datatransfer::XTransferable > CreateTransferable(const EditSelection &rSelection)
Definition: editeng.cxx:814
sal_Int32 GetTextLen() const
Definition: editeng.cxx:584
EditSelection CreateSelection(const ESelection &rSel)
Definition: editeng.cxx:945
EditSelection InsertText(css::uno::Reference< css::datatransfer::XTransferable > const &rxDataObj, const OUString &rBaseURL, const EditPaM &rPaM, bool bUseSpecial)
EditPaM InsertParaBreak(const EditSelection &rEditSelection)
Definition: editeng.cxx:2865
EditPaM & Min()
Definition: editdoc.hxx:705
virtual OUString GetText(sal_Int32 nPara) const =0
NonOverflowingText(const ESelection &aSel, bool bLastParaInterrupted)
ESelection GetOverflowPointSel() const
bool IsLastParaInterrupted() const
std::optional< OutlinerParaObject > RemoveOverflowingText(Outliner *) const
std::optional< NonOverflowingText > mpNonOverflowingTxt
std::optional< OutlinerParaObject > InsertOverflowingText(Outliner *, OutlinerParaObject const *)
bool IsLastParaInterrupted() const
std::optional< OverflowingText > mpOverflowingTxt
std::optional< OutlinerParaObject > RemoveOverflowingText(Outliner *)
ESelection GetOverflowPointSel() const
OFlowChainedText(Outliner const *, bool)
const EditTextObject & GetTextObject() const
Definition: outlobj.cxx:189
void SetText(const OutlinerParaObject &)
Definition: outliner.cxx:559
const EditEngine & GetEditEngine() const
Definition: outlin2.cxx:515
std::optional< OutlinerParaObject > CreateParaObject(sal_Int32 nStartPara=0, sal_Int32 nParaCount=EE_PARA_ALL) const
Definition: outliner.cxx:361
std::optional< NonOverflowingText > GetNonOverflowingText() const
Definition: outliner.cxx:1987
void QuickDelete(const ESelection &rSel)
Definition: outlin2.cxx:457
std::optional< OverflowingText > GetOverflowingText() const
Definition: outliner.cxx:2100
void SetToEmptyText()
Definition: outliner.cxx:392
sal_Int32 GetParagraphCount() const
Definition: outliner.cxx:1340
std::optional< OutlinerParaObject > DeeplyMergeParaObject(Outliner *, OutlinerParaObject const *)
OverflowingText(css::uno::Reference< css::datatransfer::XTransferable > xOverflowingContent)
css::uno::Reference< css::datatransfer::XTransferable > mxOverflowingContent
std::optional< OutlinerParaObject > JuxtaposeParaObject(Outliner *, OutlinerParaObject const *)
static css::uno::Reference< css::datatransfer::XTransferable > CreateTransferableFromText(Outliner const *)
static std::optional< OutlinerParaObject > JuxtaposeParaObject(css::uno::Reference< css::datatransfer::XTransferable > const &xOverflowingContent, Outliner *, OutlinerParaObject const *)
static std::optional< OutlinerParaObject > DeeplyMergeParaObject(css::uno::Reference< css::datatransfer::XTransferable > const &xOverflowingContent, Outliner *, OutlinerParaObject const *)
std::optional< OutlinerParaObject > CreateMergedUnderflowParaObject(Outliner *, OutlinerParaObject const *)
UFlowChainedText(Outliner const *, bool)
css::uno::Reference< css::datatransfer::XTransferable > mxUnderflowingTxt
Specialise std::optional template for the case where we are wrapping a o3tl::cow_wrapper type,...
Definition: outlobj.hxx:133
#define SAL_INFO(area, stream)
sal_Int32 nStartPara
Definition: editdata.hxx:113
sal_Int32 nEndPos
Definition: editdata.hxx:116
sal_Int32 nStartPos
Definition: editdata.hxx:114
sal_Int32 nEndPara
Definition: editdata.hxx:115