tdf#161411 - UI: Add Better wording for ASCII-only characters
[LibreOffice.git] / svx / source / svdraw / textchainflow.cxx
blobb41d208e221b6b5552a68bd313ccaae5b56f9a2a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <svx/svdotext.hxx>
22 #include <svx/svdoutl.hxx>
23 #include <editeng/outlobj.hxx>
24 #include <editeng/editobj.hxx>
25 #include <editeng/overflowingtxt.hxx>
26 #include <textchainflow.hxx>
27 #include <sal/log.hxx>
29 TextChainFlow::TextChainFlow(SdrTextObj *pChainTarget)
30 : mpTargetLink(pChainTarget)
32 SAL_INFO("svx.chaining", "[TEXTCHAINFLOW] Creating a new TextChainFlow");
34 mpTextChain = mpTargetLink->GetTextChain();
35 mpNextLink = mpTargetLink->GetNextLinkInChain();
37 bUnderflow = bOverflow = false;
39 mbOFisUFinduced = false;
41 mpOverflChText = nullptr;
42 mpUnderflChText = nullptr;
44 mbPossiblyCursorOut = false;
48 TextChainFlow::~TextChainFlow()
50 mpOverflChText.reset();
51 mpUnderflChText.reset();
54 void TextChainFlow::impSetFlowOutlinerParams(SdrOutliner *, SdrOutliner *)
56 // Nothing to do if not in editing mode
60 * Check for overflow in the state of pFlowOutl.
61 * If pParamOutl is not NULL sets some parameters from there.
62 * This is useful in case the outliner is not set for overflow
63 * (e.g. in editing mode we check for overflow in drawing outl but
64 * parameters come from editing outliner)
66 void TextChainFlow::impCheckForFlowEvents(SdrOutliner *pFlowOutl, SdrOutliner *pParamOutl)
68 bool bOldUpdateMode = pFlowOutl->IsUpdateLayout();
70 // XXX: This could be reorganized moving most of this stuff inside EditingTextChainFlow
71 if (pParamOutl != nullptr)
73 // We need this since it's required to check overflow
74 pFlowOutl->SetUpdateLayout(true);
76 // XXX: does this work if you do it before setting the text? Seems so.
77 impSetFlowOutlinerParams(pFlowOutl, pParamOutl);
80 bool bIsPageOverflow = pFlowOutl->IsPageOverflow();
82 // NOTE: overflow and underflow cannot be both true
83 bOverflow = bIsPageOverflow && mpNextLink;
84 bUnderflow = !bIsPageOverflow && mpNextLink && mpNextLink->HasText();
86 // Get old state on whether to merge para-s or not
87 // NOTE: We handle UF/OF using the _old_ state. The new one is simply saved
88 bool bMustMergeParaAmongLinks = GetTextChain()->GetIsPartOfLastParaInNextLink(mpTargetLink);
90 // Set (Non)OverflowingTxt here (if any)
92 // If we had an underflow before we have to deep merge paras anyway
93 bool bMustMergeParaOF = bMustMergeParaAmongLinks || mbOFisUFinduced;
95 mpOverflChText.reset( bOverflow ?
96 new OFlowChainedText(pFlowOutl, bMustMergeParaOF) :
97 nullptr );
99 // Set current underflowing text (if any)
100 mpUnderflChText.reset( bUnderflow ?
101 new UFlowChainedText(pFlowOutl, bMustMergeParaAmongLinks) :
102 nullptr );
104 // Reset update mode // Reset it here because we use WriteRTF (needing updatemode = true) in the two constructors above
105 if (!bOldUpdateMode) // Reset only if the old value was false
106 pFlowOutl->SetUpdateLayout(bOldUpdateMode);
108 // NOTE: Must be called after mp*ChText and b*flow have been set but before mbOFisUFinduced is reset
109 impUpdateCursorInfo();
111 // To check whether an overflow is underflow induced or not (useful in cursor checking)
112 mbOFisUFinduced = bUnderflow;
115 void TextChainFlow::impUpdateCursorInfo()
117 // XXX: Maybe we can get rid of mbOFisUFinduced by not allowing handling of more than one event by the same TextChainFlow
118 // if this is not an OF triggered during an UF
120 mbPossiblyCursorOut = bOverflow;
122 if(mbPossiblyCursorOut ) {
123 maOverflowPosSel = mpOverflChText->GetOverflowPointSel();
124 ESelection aSelAtUFTime = GetTextChain()->GetPreChainingSel(GetLinkTarget());
125 // Might be an invalid selection if the cursor at UF time was before
126 // the (possibly UF-induced) Overflowing point but we don't use it in that case
127 maPostChainingSel = ESelection(aSelAtUFTime.start.nPara-maOverflowPosSel.start.nPara,
128 aSelAtUFTime.start.nIndex-maOverflowPosSel.start.nIndex );
131 // XXX: It may not be necessary anymore to keep this method separated from EditingTextChainFlow::impBroadcastCursorInfo
134 void TextChainFlow::CheckForFlowEvents(SdrOutliner *pFlowOutl)
136 impCheckForFlowEvents(pFlowOutl, nullptr);
140 bool TextChainFlow::IsOverflow() const
142 return bOverflow;
145 bool TextChainFlow::IsUnderflow() const
147 return bUnderflow;
151 // XXX: In editing mode you need to get "underflowing" text from editing outliner, so it's kinda separated from the drawing one!
153 // XXX:Would it be possible to unify underflow and its possibly following overflow?
154 void TextChainFlow::ExecuteUnderflow(SdrOutliner *pOutl)
156 //GetTextChain()->SetNilChainingEvent(mpTargetLink, true);
157 // making whole text
158 // merges underflowing text with the one in the next box
159 std::optional<OutlinerParaObject> pNewText = mpUnderflChText->CreateMergedUnderflowParaObject(pOutl, mpNextLink->GetOutlinerParaObject());
161 // Set the other box empty; it will be replaced by the rest of the text if overflow occurs
162 if (!mpTargetLink->GetPreventChainable())
163 mpNextLink->NbcSetOutlinerParaObject(pOutl->GetEmptyParaObject());
165 // We store the size since NbcSetOutlinerParaObject can change it
166 //Size aOldSize = pOutl->GetMaxAutoPaperSize();
168 // This should not be done in editing mode!! //XXX
169 if (!mpTargetLink->IsInEditMode())
171 mpTargetLink->NbcSetOutlinerParaObject(pNewText);
174 // Restore size and set new text
175 //pOutl->SetMaxAutoPaperSize(aOldSize); // XXX (it seems to be working anyway without this)
176 pOutl->SetText(*pNewText);
178 //GetTextChain()->SetNilChainingEvent(mpTargetLink, false);
180 // Check for new overflow
181 CheckForFlowEvents(pOutl);
184 void TextChainFlow::ExecuteOverflow(SdrOutliner *pNonOverflOutl, SdrOutliner *pOverflOutl)
186 //GetTextChain()->SetNilChainingEvent(mpTargetLink, true);
187 // Leave only non overflowing text
188 impLeaveOnlyNonOverflowingText(pNonOverflOutl);
190 // Transfer of text to next link
191 if (!mpTargetLink->GetPreventChainable() ) // we don't transfer text while dragging because of resizing
193 impMoveChainedTextToNextLink(pOverflOutl);
196 //GetTextChain()->SetNilChainingEvent(mpTargetLink, false);
199 void TextChainFlow::impLeaveOnlyNonOverflowingText(SdrOutliner *pNonOverflOutl)
201 std::optional<OutlinerParaObject> pNewText = mpOverflChText->RemoveOverflowingText(pNonOverflOutl);
203 SAL_INFO("svx.chaining", "[TEXTCHAINFLOW - OF] SOURCE box set to "
204 << pNewText->GetTextObject().GetParagraphCount() << " paras");
206 // adds it to current outliner anyway (useful in static decomposition)
207 pNonOverflOutl->SetText(*pNewText);
209 mpTargetLink->NbcSetOutlinerParaObject(std::move(pNewText));
210 // For some reason the paper size is lost after last instruction, so we set it.
211 pNonOverflOutl->SetPaperSize(Size(pNonOverflOutl->GetPaperSize().Width(),
212 pNonOverflOutl->GetTextHeight()));
216 void TextChainFlow::impMoveChainedTextToNextLink(SdrOutliner *pOverflOutl)
218 // prevent copying text in same box
219 if ( mpNextLink == mpTargetLink ) {
220 SAL_INFO("svx.chaining", "[CHAINING] Trying to copy text for next link in same object");
221 return;
224 std::optional<OutlinerParaObject> pNewText =
225 mpOverflChText->InsertOverflowingText(pOverflOutl,
226 mpNextLink->GetOutlinerParaObject());
227 SAL_INFO("svx.chaining", "[TEXTCHAINFLOW - OF] DEST box set to "
228 << pNewText->GetTextObject().GetParagraphCount() << " paras");
230 if (pNewText)
231 mpNextLink->NbcSetOutlinerParaObject(std::move(pNewText));
233 // Set Deep Merge status
234 SAL_INFO("svx.chaining", "[DEEPMERGE] Setting deepMerge to "
235 << mpOverflChText->IsLastParaInterrupted());
236 GetTextChain()->SetIsPartOfLastParaInNextLink(
237 mpTargetLink,
238 mpOverflChText->IsLastParaInterrupted());
241 SdrTextObj *TextChainFlow::GetLinkTarget() const
243 return mpTargetLink;
246 TextChain *TextChainFlow::GetTextChain() const
248 return mpTextChain;
251 // EditingTextChainFlow
253 EditingTextChainFlow::EditingTextChainFlow(SdrTextObj *pLinkTarget) :
254 TextChainFlow(pLinkTarget)
256 SAL_INFO("svx.chaining", "[TEXTCHAINFLOW] Creating a new EditingTextChainFlow");
259 void EditingTextChainFlow::CheckForFlowEvents(SdrOutliner *pFlowOutl)
261 // if this is editing outliner no need to set parameters
262 if (pFlowOutl == GetLinkTarget()->mpEditingOutliner)
263 impCheckForFlowEvents(pFlowOutl, nullptr);
264 else
265 impCheckForFlowEvents(pFlowOutl, GetLinkTarget()->mpEditingOutliner);
267 // Broadcast events for cursor handling
268 impBroadcastCursorInfo();
271 void EditingTextChainFlow::impLeaveOnlyNonOverflowingText(SdrOutliner *pNonOverflOutl)
273 mpOverflChText->RemoveOverflowingText(pNonOverflOutl);
274 //impSetTextForEditingOutliner(pNewText); //XXX: Don't call it since we do everything with NonOverflowingText::ToParaObject // XXX: You may need this for Underflow
276 // XXX: I'm not sure whether we need this (after all operations such as Paste don't change this - as far as I understand)
277 //GetLinkTarget()->NbcSetOutlinerParaObject(pNewText);
280 void EditingTextChainFlow::impSetFlowOutlinerParams(SdrOutliner *pFlowOutl, SdrOutliner *pParamOutl)
282 // Set right size for overflow
283 pFlowOutl->SetMaxAutoPaperSize(pParamOutl->GetMaxAutoPaperSize());
284 pFlowOutl->SetMinAutoPaperSize(pParamOutl->GetMinAutoPaperSize());
285 pFlowOutl->SetPaperSize(pParamOutl->GetPaperSize());
288 void EditingTextChainFlow::impBroadcastCursorInfo() const
290 ESelection aPreChainingSel = GetTextChain()->GetPreChainingSel(GetLinkTarget()) ;
292 // Test whether the cursor is out of the box.
293 bool bCursorOut = mbPossiblyCursorOut && maOverflowPosSel < aPreChainingSel;
295 // NOTE: I handled already the stuff for the comments below. They will be kept temporarily till stuff settles down.
296 // Possibility: 1) why don't we stop passing the actual event to the TextChain and instead we pass
297 // the overflow pos and mbPossiblyCursorOut
298 // 2) We pass the current selection before anything happens and we make impBroadcastCursorInfo compute it.
301 if (bCursorOut) {
302 //maCursorEvent = CursorChainingEvent::TO_NEXT_LINK;
303 GetTextChain()->SetPostChainingSel(GetLinkTarget(), maPostChainingSel);
304 GetTextChain()->SetCursorEvent(GetLinkTarget(), CursorChainingEvent::TO_NEXT_LINK);
305 } else {
306 //maCursorEvent = CursorChainingEvent::UNCHANGED;
307 GetTextChain()->SetPostChainingSel(GetLinkTarget(), aPreChainingSel);
308 GetTextChain()->SetCursorEvent(GetLinkTarget(), CursorChainingEvent::UNCHANGED);
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */