]> git.lyx.org Git - lyx.git/blob - src/CutAndPaste.cpp
Make LaTeX export threadsafe.
[lyx.git] / src / CutAndPaste.cpp
1 /**
2  * \file CutAndPaste.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  * \author Lars Gullik Bjønnes
8  * \author Alfredo Braunstein
9  * \author Michael Gerz
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "CutAndPaste.h"
17
18 #include "BranchList.h"
19 #include "Buffer.h"
20 #include "buffer_funcs.h"
21 #include "BufferList.h"
22 #include "BufferParams.h"
23 #include "BufferView.h"
24 #include "Changes.h"
25 #include "Cursor.h"
26 #include "Encoding.h"
27 #include "ErrorList.h"
28 #include "FuncCode.h"
29 #include "FuncRequest.h"
30 #include "InsetIterator.h"
31 #include "InsetList.h"
32 #include "Language.h"
33 #include "LyX.h"
34 #include "LyXRC.h"
35 #include "Text.h"
36 #include "Paragraph.h"
37 #include "ParagraphParameters.h"
38 #include "ParIterator.h"
39 #include "TextClass.h"
40
41 #include "insets/InsetBibitem.h"
42 #include "insets/InsetBranch.h"
43 #include "insets/InsetCommand.h"
44 #include "insets/InsetFlex.h"
45 #include "insets/InsetGraphics.h"
46 #include "insets/InsetGraphicsParams.h"
47 #include "insets/InsetInclude.h"
48 #include "insets/InsetLabel.h"
49 #include "insets/InsetTabular.h"
50
51 #include "mathed/MathData.h"
52 #include "mathed/InsetMath.h"
53 #include "mathed/InsetMathHull.h"
54 #include "mathed/InsetMathRef.h"
55 #include "mathed/MathSupport.h"
56
57 #include "support/debug.h"
58 #include "support/docstream.h"
59 #include "support/gettext.h"
60 #include "support/lassert.h"
61 #include "support/limited_stack.h"
62 #include "support/lstrings.h"
63 #include "support/TempFile.h"
64
65 #include "frontends/alert.h"
66 #include "frontends/Clipboard.h"
67 #include "frontends/Selection.h"
68
69 #include <boost/tuple/tuple.hpp>
70 #include <boost/next_prior.hpp>
71
72 #include <string>
73
74 using namespace std;
75 using namespace lyx::support;
76 using lyx::frontend::Clipboard;
77
78 namespace lyx {
79
80 namespace {
81
82 typedef pair<pit_type, int> PitPosPair;
83
84 typedef limited_stack<pair<ParagraphList, DocumentClassConstPtr> > CutStack;
85
86 CutStack theCuts(10);
87 // persistent selection, cleared until the next selection
88 CutStack selectionBuffer(1);
89
90 // store whether the tabular stack is newer than the normal copy stack
91 // FIXME: this is a workaround for bug 1919. Should be removed for 1.5,
92 // when we (hopefully) have a one-for-all paste mechanism.
93 bool dirty_tabular_stack_ = false;
94
95
96 bool checkPastePossible(int index)
97 {
98         return size_t(index) < theCuts.size() && !theCuts[index].first.empty();
99 }
100
101
102 struct PasteReturnValue {
103         PasteReturnValue(pit_type r_par, pos_type r_pos, bool r_nu) :
104           par(r_par), pos(r_pos), needupdate(r_nu)
105         {}
106
107         pit_type par;
108         pos_type pos;
109         bool needupdate;
110 };
111
112 PasteReturnValue
113 pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
114                      DocumentClassConstPtr oldDocClass, Buffer * tmpbuffer,
115                      ErrorList & errorlist)
116 {
117         Buffer const & buffer = *cur.buffer();
118         pit_type pit = cur.pit();
119         pos_type pos = cur.pos();
120         bool need_update = false;
121         InsetText * target_inset = cur.inset().asInsetText();
122         if (!target_inset) {
123                 InsetTabular * it = cur.inset().asInsetTabular();
124                 target_inset = it? it->cell(cur.idx())->asInsetText() : 0;
125         }
126         LASSERT(target_inset, return PasteReturnValue(pit, pos, need_update));
127         ParagraphList & pars = target_inset->paragraphs();
128
129         if (parlist.empty())
130                 return PasteReturnValue(pit, pos, need_update);
131
132         BOOST_ASSERT (pos <= pars[pit].size());
133
134         // Make a copy of the CaP paragraphs.
135         ParagraphList insertion = parlist;
136         DocumentClassConstPtr newDocClass = buffer.params().documentClassPtr();
137
138         // Now remove all out of the pars which is NOT allowed in the
139         // new environment and set also another font if that is required.
140
141         // Convert newline to paragraph break in ParbreakIsNewline
142         if (target_inset->getLayout().parbreakIsNewline()
143             || pars[pit].layout().parbreak_is_newline) {
144                 for (size_t i = 0; i != insertion.size(); ++i) {
145                         for (pos_type j = 0; j != insertion[i].size(); ++j) {
146                                 if (insertion[i].isNewline(j)) {
147                                         // do not track deletion of newline
148                                         insertion[i].eraseChar(j, false);
149                                         insertion[i].setInsetOwner(target_inset);
150                                         breakParagraphConservative(
151                                                         buffer.params(),
152                                                         insertion, i, j);
153                                         break;
154                                 }
155                         }
156                 }
157         }
158
159         // set the paragraphs to plain layout if necessary
160         if (cur.inset().usePlainLayout()) {
161                 bool forcePlainLayout = cur.inset().forcePlainLayout();
162                 Layout const & plainLayout = newDocClass->plainLayout();
163                 Layout const & defaultLayout = newDocClass->defaultLayout();
164                 ParagraphList::iterator const end = insertion.end();
165                 ParagraphList::iterator par = insertion.begin();
166                 for (; par != end; ++par) {
167                         Layout const & parLayout = par->layout();
168                         if (forcePlainLayout || parLayout == defaultLayout)
169                                 par->setLayout(plainLayout);
170                 }
171         } else { // check if we need to reset from plain layout
172                 Layout const & defaultLayout = newDocClass->defaultLayout();
173                 Layout const & plainLayout = newDocClass->plainLayout();
174                 ParagraphList::iterator const end = insertion.end();
175                 ParagraphList::iterator par = insertion.begin();
176                 for (; par != end; ++par) {
177                         Layout const & parLayout = par->layout();
178                         if (parLayout == plainLayout)
179                                 par->setLayout(defaultLayout);
180                 }
181         }
182
183         InsetText in(cur.buffer());
184         // Make sure there is no class difference.
185         in.paragraphs().clear();
186         // This works without copying any paragraph data because we have
187         // a specialized swap method for ParagraphList. This is important
188         // since we store pointers to insets at some places and we don't
189         // want to invalidate them.
190         insertion.swap(in.paragraphs());
191         cap::switchBetweenClasses(oldDocClass, newDocClass, in, errorlist);
192         insertion.swap(in.paragraphs());
193
194         ParagraphList::iterator tmpbuf = insertion.begin();
195         int depth_delta = pars[pit].params().depth() - tmpbuf->params().depth();
196
197         depth_type max_depth = pars[pit].getMaxDepthAfter();
198
199         for (; tmpbuf != insertion.end(); ++tmpbuf) {
200                 // If we have a negative jump so that the depth would
201                 // go below 0 depth then we have to redo the delta to
202                 // this new max depth level so that subsequent
203                 // paragraphs are aligned correctly to this paragraph
204                 // at level 0.
205                 if (int(tmpbuf->params().depth()) + depth_delta < 0)
206                         depth_delta = 0;
207
208                 // Set the right depth so that we are not too deep or shallow.
209                 tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
210                 if (tmpbuf->params().depth() > max_depth)
211                         tmpbuf->params().depth(max_depth);
212
213                 // Set max_depth for the next paragraph
214                 max_depth = tmpbuf->getMaxDepthAfter();
215
216                 // Set the inset owner of this paragraph.
217                 tmpbuf->setInsetOwner(target_inset);
218                 for (pos_type i = 0; i < tmpbuf->size(); ++i) {
219                         // do not track deletion of invalid insets
220                         if (Inset * inset = tmpbuf->getInset(i))
221                                 if (!target_inset->insetAllowed(inset->lyxCode()))
222                                         tmpbuf->eraseChar(i--, false);
223                 }
224
225                 tmpbuf->setChange(Change(buffer.params().track_changes ?
226                                          Change::INSERTED : Change::UNCHANGED));
227         }
228
229         bool const empty = pars[pit].empty();
230         if (!empty) {
231                 // Make the buf exactly the same layout as the cursor
232                 // paragraph.
233                 insertion.begin()->makeSameLayout(pars[pit]);
234         }
235
236         // Prepare the paragraphs and insets for insertion.
237         insertion.swap(in.paragraphs());
238
239         InsetIterator const i_end = inset_iterator_end(in);
240         for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
241                 // Even though this will also be done later, it has to be done here 
242                 // since some inset might going to try to access
243                 // the buffer() member.
244                 it->setBuffer(const_cast<Buffer &>(buffer));
245                 switch (it->lyxCode()) {
246
247                 case MATH_HULL_CODE: {
248                         // check for equation labels and resolve duplicates
249                         InsetMathHull * ins = it->asInsetMath()->asHullInset();
250                         std::vector<InsetLabel *> labels = ins->getLabels();
251                         for (size_t i = 0; i != labels.size(); ++i) {
252                                 if (!labels[i])
253                                         continue;
254                                 InsetLabel * lab = labels[i];
255                                 docstring const oldname = lab->getParam("name");
256                                 lab->updateLabel(oldname);
257                                 // We need to update the buffer reference cache.
258                                 need_update = true;
259                                 docstring const newname = lab->getParam("name");
260                                 if (oldname == newname)
261                                         continue;
262                                 // adapt the references
263                                 for (InsetIterator itt = inset_iterator_begin(in);
264                                       itt != i_end; ++itt) {
265                                         if (itt->lyxCode() == REF_CODE) {
266                                                 InsetCommand * ref = itt->asInsetCommand();
267                                                 if (ref->getParam("reference") == oldname)
268                                                         ref->setParam("reference", newname);
269                                         } else if (itt->lyxCode() == MATH_REF_CODE) {
270                                                 InsetMathRef * mi = itt->asInsetMath()->asRefInset();
271                                                 // this is necessary to prevent an uninitialized
272                                                 // buffer when the RefInset is in a MathBox.
273                                                 // FIXME audit setBuffer calls
274                                                 mi->setBuffer(const_cast<Buffer &>(buffer));
275                                                 if (mi->getTarget() == oldname)
276                                                         mi->changeTarget(newname);
277                                         }
278                                 }
279                         }
280                         break;
281                 }
282
283                 case LABEL_CODE: {
284                         // check for duplicates
285                         InsetLabel & lab = static_cast<InsetLabel &>(*it);
286                         docstring const oldname = lab.getParam("name");
287                         lab.updateLabel(oldname);
288                         // We need to update the buffer reference cache.
289                         need_update = true;
290                         docstring const newname = lab.getParam("name");
291                         if (oldname == newname)
292                                 break;
293                         // adapt the references
294                         for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
295                                 if (itt->lyxCode() == REF_CODE) {
296                                         InsetCommand & ref = static_cast<InsetCommand &>(*itt);
297                                         if (ref.getParam("reference") == oldname)
298                                                 ref.setParam("reference", newname);
299                                 } else if (itt->lyxCode() == MATH_REF_CODE) {
300                                         InsetMathRef * mi = itt->asInsetMath()->asRefInset();
301                                         // this is necessary to prevent an uninitialized
302                                         // buffer when the RefInset is in a MathBox.
303                                         // FIXME audit setBuffer calls
304                                         mi->setBuffer(const_cast<Buffer &>(buffer));
305                                         if (mi->getTarget() == oldname)
306                                                 mi->changeTarget(newname);
307                                 }
308                         }
309                         break;
310                 }
311
312                 case INCLUDE_CODE: {
313                         InsetInclude & inc = static_cast<InsetInclude &>(*it);
314                         inc.updateCommand();
315                         // We need to update the list of included files.
316                         need_update = true;
317                         break;
318                 }
319
320                 case BIBITEM_CODE: {
321                         // check for duplicates
322                         InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
323                         docstring const oldkey = bib.getParam("key");
324                         bib.updateCommand(oldkey, false);
325                         // We need to update the buffer reference cache.
326                         need_update = true;
327                         docstring const newkey = bib.getParam("key");
328                         if (oldkey == newkey)
329                                 break;
330                         // adapt the references
331                         for (InsetIterator itt = inset_iterator_begin(in);
332                              itt != i_end; ++itt) {
333                                 if (itt->lyxCode() == CITE_CODE) {
334                                         InsetCommand * ref = itt->asInsetCommand();
335                                         if (ref->getParam("key") == oldkey)
336                                                 ref->setParam("key", newkey);
337                                 }
338                         }
339                         break;
340                 }
341
342                 case BRANCH_CODE: {
343                         // check if branch is known to target buffer
344                         // or its master
345                         InsetBranch & br = static_cast<InsetBranch &>(*it);
346                         docstring const name = br.branch();
347                         if (name.empty())
348                                 break;
349                         bool const is_child = (&buffer != buffer.masterBuffer());
350                         BranchList branchlist = buffer.params().branchlist();
351                         if ((!is_child && branchlist.find(name))
352                             || (is_child && (branchlist.find(name)
353                                 || buffer.masterBuffer()->params().branchlist().find(name))))
354                                 break;
355                         if (tmpbuffer) {
356                                 // This is for a temporary buffer, so simply create the branch.
357                                 // Must not use lyx::dispatch(), since tmpbuffer has no view.
358                                 DispatchResult dr;
359                                 tmpbuffer->dispatch(FuncRequest(LFUN_BRANCH_ADD, name), dr);
360                         } else {
361                                 docstring text = bformat(
362                                         _("The pasted branch \"%1$s\" is undefined.\n"
363                                           "Do you want to add it to the document's branch list?"),
364                                         name);
365                                 if (frontend::Alert::prompt(_("Unknown branch"),
366                                           text, 0, 1, _("&Add"), _("&Don't Add")) != 0)
367                                         break;
368                                 lyx::dispatch(FuncRequest(LFUN_BRANCH_ADD, name));
369                         }
370                         // We need to update the list of branches.
371                         need_update = true;
372                         break;
373                 }
374
375                 default:
376                         break; // nothing
377                 }
378         }
379         insertion.swap(in.paragraphs());
380
381         // Split the paragraph for inserting the buf if necessary.
382         if (!empty)
383                 breakParagraphConservative(buffer.params(), pars, pit, pos);
384
385         // Paste it!
386         if (empty) {
387                 pars.insert(boost::next(pars.begin(), pit),
388                             insertion.begin(),
389                             insertion.end());
390
391                 // merge the empty par with the last par of the insertion
392                 mergeParagraph(buffer.params(), pars,
393                                pit + insertion.size() - 1);
394         } else {
395                 pars.insert(boost::next(pars.begin(), pit + 1),
396                             insertion.begin(),
397                             insertion.end());
398
399                 // merge the first par of the insertion with the current par
400                 mergeParagraph(buffer.params(), pars, pit);
401         }
402
403         // Store the new cursor position.
404         pit_type last_paste = pit + insertion.size() - 1;
405         pit_type startpit = pit;
406         pit = last_paste;
407         pos = pars[last_paste].size();
408
409         // FIXME Should we do it here, or should we let updateBuffer() do it?
410         // Set paragraph buffers. It's important to do this right away
411         // before something calls Inset::buffer() and causes a crash.
412         for (pit_type p = startpit; p <= pit; ++p)
413                 pars[p].setBuffer(const_cast<Buffer &>(buffer));
414
415         // Join (conditionally) last pasted paragraph with next one, i.e.,
416         // the tail of the spliced document paragraph
417         if (!empty && last_paste + 1 != pit_type(pars.size())) {
418                 if (pars[last_paste + 1].hasSameLayout(pars[last_paste])) {
419                         mergeParagraph(buffer.params(), pars, last_paste);
420                 } else if (pars[last_paste + 1].empty()) {
421                         pars[last_paste + 1].makeSameLayout(pars[last_paste]);
422                         mergeParagraph(buffer.params(), pars, last_paste);
423                 } else if (pars[last_paste].empty()) {
424                         pars[last_paste].makeSameLayout(pars[last_paste + 1]);
425                         mergeParagraph(buffer.params(), pars, last_paste);
426                 } else {
427                         pars[last_paste + 1].stripLeadingSpaces(buffer.params().track_changes);
428                         ++last_paste;
429                 }
430         }
431
432         return PasteReturnValue(pit, pos, need_update);
433 }
434
435
436 PitPosPair eraseSelectionHelper(BufferParams const & params,
437         ParagraphList & pars,
438         pit_type startpit, pit_type endpit,
439         int startpos, int endpos)
440 {
441         // Start of selection is really invalid.
442         if (startpit == pit_type(pars.size()) ||
443             (startpos > pars[startpit].size()))
444                 return PitPosPair(endpit, endpos);
445
446         // Start and end is inside same paragraph
447         if (endpit == pit_type(pars.size()) || startpit == endpit) {
448                 endpos -= pars[startpit].eraseChars(startpos, endpos, params.track_changes);
449                 return PitPosPair(endpit, endpos);
450         }
451
452         for (pit_type pit = startpit; pit != endpit + 1;) {
453                 pos_type const left  = (pit == startpit ? startpos : 0);
454                 pos_type right = (pit == endpit ? endpos : pars[pit].size() + 1);
455                 bool const merge = pars[pit].isMergedOnEndOfParDeletion(params.track_changes);
456
457                 // Logically erase only, including the end-of-paragraph character
458                 pars[pit].eraseChars(left, right, params.track_changes);
459
460                 // Separate handling of paragraph break:
461                 if (merge && pit != endpit &&
462                     (pit + 1 != endpit 
463                      || pars[pit].hasSameLayout(pars[endpit])
464                      || pars[endpit].size() == endpos)) {
465                         if (pit + 1 == endpit)
466                                 endpos += pars[pit].size();
467                         mergeParagraph(params, pars, pit);
468                         --endpit;
469                 } else
470                         ++pit;
471         }
472
473         // Ensure legal cursor pos:
474         endpit = startpit;
475         endpos = startpos;
476         return PitPosPair(endpit, endpos);
477 }
478
479
480 void putClipboard(ParagraphList const & paragraphs, 
481         DocumentClassConstPtr docclass, docstring const & plaintext)
482 {
483         // This used to need to be static to avoid a memory leak. It no longer needs
484         // to be so, but the alternative is to construct a new one of these (with a
485         // new temporary directory, etc) every time, and then to destroy it. So maybe
486         // it's worth just keeping this one around.
487         // FIXME THREAD
488         static TempFile tempfile("clipboard.internal");
489         tempfile.setAutoRemove(false);
490         static Buffer * staticbuffer = theBufferList().newInternalBuffer(
491                         tempfile.name().absFileName());
492
493         // These two things only really need doing the first time.
494         staticbuffer->setUnnamed(true);
495         staticbuffer->inset().setBuffer(*staticbuffer);
496
497         // Use a clone for the complicated stuff so that we do not need to clean
498         // up in order to avoid a crash.
499         Buffer * buffer = staticbuffer->cloneBufferOnly();
500         LASSERT(buffer, return);
501
502         // This needs doing every time.
503         buffer->params().setDocumentClass(docclass);
504
505         // we will use pasteSelectionHelper to copy the paragraphs into the
506         // temporary Buffer, since it does a lot of things to fix them up.
507         DocIterator dit = doc_iterator_begin(buffer, &buffer->inset());
508         ErrorList el;
509         pasteSelectionHelper(dit, paragraphs, docclass, buffer, el);
510
511         // We don't want to produce images that are not used. Therefore,
512         // output formulas as MathML. Even if this is not understood by all
513         // applications, the number that can parse it should go up in the future.
514         buffer->params().html_math_output = BufferParams::MathML;
515
516         // Make sure MarkAsExporting is deleted before buffer is
517         {
518                 // The Buffer is being used to export. This is necessary so that the
519                 // updateMacros call will record the needed information.
520                 MarkAsExporting mex(buffer);
521
522                 buffer->updateBuffer(Buffer::UpdateMaster, OutputUpdate);
523                 buffer->updateMacros();
524                 buffer->updateMacroInstances(OutputUpdate);
525
526                 // LyX's own format
527                 string lyx;
528                 ostringstream oslyx;
529                 if (buffer->write(oslyx))
530                         lyx = oslyx.str();
531
532                 // XHTML format
533                 odocstringstream oshtml;
534                 OutputParams runparams(encodings.fromLyXName("utf8"));
535                 // We do not need to produce images, etc.
536                 runparams.dryrun = true;
537                 // We are not interested in errors (bug 8866)
538                 runparams.silent = true;
539                 buffer->writeLyXHTMLSource(oshtml, runparams, Buffer::FullSource);
540
541                 theClipboard().put(lyx, oshtml.str(), plaintext);
542         }
543
544         // Save that memory
545         delete buffer;
546 }
547
548
549 /// return true if the whole ParagraphList is deleted
550 static bool isFullyDeleted(ParagraphList const & pars)
551 {
552         pit_type const pars_size = static_cast<pit_type>(pars.size());
553
554         // check all paragraphs
555         for (pit_type pit = 0; pit < pars_size; ++pit) {
556                 if (!pars[pit].empty())   // prevent assertion failure
557                         if (!pars[pit].isDeleted(0, pars[pit].size()))
558                                 return false;
559         }
560         return true;
561 }
562
563
564 void copySelectionHelper(Buffer const & buf, Text const & text,
565         pit_type startpit, pit_type endpit,
566         int start, int end, DocumentClassConstPtr dc, CutStack & cutstack)
567 {
568         ParagraphList const & pars = text.paragraphs();
569
570         // In most of these cases, we can try to recover.
571         LASSERT(0 <= start, start = 0);
572         LASSERT(start <= pars[startpit].size(), start = pars[startpit].size());
573         LASSERT(0 <= end, end = 0);
574         LASSERT(end <= pars[endpit].size(), end = pars[endpit].size());
575         LASSERT(startpit != endpit || start <= end, return);
576
577         // Clone the paragraphs within the selection.
578         ParagraphList copy_pars(boost::next(pars.begin(), startpit),
579                                 boost::next(pars.begin(), endpit + 1));
580
581         // Remove the end of the last paragraph; afterwards, remove the
582         // beginning of the first paragraph. Keep this order - there may only
583         // be one paragraph!  Do not track deletions here; this is an internal
584         // action not visible to the user
585
586         Paragraph & back = copy_pars.back();
587         back.eraseChars(end, back.size(), false);
588         Paragraph & front = copy_pars.front();
589         front.eraseChars(0, start, false);
590
591         ParagraphList::iterator it = copy_pars.begin();
592         ParagraphList::iterator it_end = copy_pars.end();
593
594         for (; it != it_end; ++it) {
595                 // Since we have a copy of the paragraphs, the insets
596                 // do not have a proper buffer reference. It makes
597                 // sense to add them temporarily, because the
598                 // operations below depend on that (acceptChanges included).
599                 it->setBuffer(const_cast<Buffer &>(buf));
600                 // PassThru paragraphs have the Language
601                 // latex_language. This is invalid for others, so we
602                 // need to change it to the buffer language.
603                 if (it->isPassThru())
604                         it->changeLanguage(buf.params(), 
605                                            latex_language, buf.language());
606         }
607
608         // do not copy text (also nested in insets) which is marked as
609         // deleted, unless the whole selection was deleted
610         if (!isFullyDeleted(copy_pars))
611                 acceptChanges(copy_pars, buf.params());
612         else
613                 rejectChanges(copy_pars, buf.params());
614
615
616         // do some final cleanup now, to make sure that the paragraphs
617         // are not linked to something else.
618         it = copy_pars.begin();
619         for (; it != it_end; ++it) {
620                 it->setBuffer(*static_cast<Buffer *>(0));
621                 it->setInsetOwner(0);
622         }
623
624         cutstack.push(make_pair(copy_pars, dc));
625 }
626
627 } // namespace anon
628
629
630
631
632 namespace cap {
633
634 void region(CursorSlice const & i1, CursorSlice const & i2,
635             Inset::row_type & r1, Inset::row_type & r2,
636             Inset::col_type & c1, Inset::col_type & c2)
637 {
638         Inset & p = i1.inset();
639         c1 = p.col(i1.idx());
640         c2 = p.col(i2.idx());
641         if (c1 > c2)
642                 swap(c1, c2);
643         r1 = p.row(i1.idx());
644         r2 = p.row(i2.idx());
645         if (r1 > r2)
646                 swap(r1, r2);
647 }
648
649
650 docstring grabAndEraseSelection(Cursor & cur)
651 {
652         if (!cur.selection())
653                 return docstring();
654         docstring res = grabSelection(cur);
655         eraseSelection(cur);
656         return res;
657 }
658
659
660 bool reduceSelectionToOneCell(Cursor & cur)
661 {
662         if (!cur.selection() || !cur.inMathed())
663                 return false;
664
665         CursorSlice i1 = cur.selBegin();
666         CursorSlice i2 = cur.selEnd();
667         if (!i1.inset().asInsetMath())
668                 return false;
669
670         // the easy case: do nothing if only one cell is selected
671         if (i1.idx() == i2.idx())
672                 return true;
673         
674         cur.top().pos() = 0;
675         cur.resetAnchor();
676         cur.top().pos() = cur.top().lastpos();
677         
678         return true;
679 }
680
681
682 bool multipleCellsSelected(Cursor const & cur)
683 {
684         if (!cur.selection() || !cur.inMathed())
685                 return false;
686         
687         CursorSlice i1 = cur.selBegin();
688         CursorSlice i2 = cur.selEnd();
689         if (!i1.inset().asInsetMath())
690                 return false;
691         
692         if (i1.idx() == i2.idx())
693                 return false;
694         
695         return true;
696 }
697
698
699 void switchBetweenClasses(DocumentClassConstPtr oldone,
700                 DocumentClassConstPtr newone, InsetText & in, ErrorList & errorlist)
701 {
702         errorlist.clear();
703
704         LBUFERR(!in.paragraphs().empty());
705         if (oldone == newone)
706                 return;
707         
708         DocumentClass const & oldtc = *oldone;
709         DocumentClass const & newtc = *newone;
710
711         // layouts
712         ParIterator it = par_iterator_begin(in);
713         ParIterator end = par_iterator_end(in);
714         // for remembering which layouts we've had to add
715         set<docstring> newlayouts;
716         for (; it != end; ++it) {
717                 docstring const name = it->layout().name();
718
719                 // the pasted text will keep their own layout name. If this layout does
720                 // not exist in the new document, it will behave like a standard layout.
721                 bool const added_one = newtc.addLayoutIfNeeded(name);
722                 if (added_one)
723                         newlayouts.insert(name);
724
725                 if (added_one || newlayouts.find(name) != newlayouts.end()) {
726                         // Warn the user.
727                         docstring const s = bformat(_("Layout `%1$s' was not found."), name);
728                         errorlist.push_back(
729                                 ErrorItem(_("Layout Not Found"), s, it->id(), 0, it->size()));
730                 }
731
732                 if (in.usePlainLayout())
733                         it->setLayout(newtc.plainLayout());
734                 else
735                         it->setLayout(newtc[name]);
736         }
737
738         // character styles
739         InsetIterator const i_end = inset_iterator_end(in);
740         for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
741                 if (it->lyxCode() != FLEX_CODE)
742                         // FIXME: Should we verify all InsetCollapsable?
743                         continue;
744
745                 docstring const layoutName = it->layoutName();
746                 docstring const & n = newone->insetLayout(layoutName).name();
747                 bool const is_undefined = n.empty() ||
748                         n == DocumentClass::plainInsetLayout().name();
749                 if (!is_undefined)
750                         continue;
751
752                 // The flex inset is undefined in newtc
753                 docstring const oldname = from_utf8(oldtc.name());
754                 docstring const newname = from_utf8(newtc.name());
755                 docstring s;
756                 if (oldname == newname)
757                         s = bformat(_("Flex inset %1$s is undefined after "
758                                 "reloading `%2$s' layout."), layoutName, oldname);
759                 else
760                         s = bformat(_("Flex inset %1$s is undefined because of "
761                                 "conversion from `%2$s' layout to `%3$s'."),
762                                 layoutName, oldname, newname);
763                 // To warn the user that something had to be done.
764                 errorlist.push_back(ErrorItem(
765                                 _("Undefined flex inset"),
766                                 s, it.paragraph().id(), it.pos(), it.pos() + 1));
767         }
768 }
769
770
771 vector<docstring> availableSelections(Buffer const * buf)
772 {
773         vector<docstring> selList;
774         if (!buf)
775                 return selList;
776
777         CutStack::const_iterator cit = theCuts.begin();
778         CutStack::const_iterator end = theCuts.end();
779         for (; cit != end; ++cit) {
780                 // we do not use cit-> here because gcc 2.9x does not
781                 // like it (JMarc)
782                 ParagraphList const & pars = (*cit).first;
783                 docstring asciiSel;
784                 ParagraphList::const_iterator pit = pars.begin();
785                 ParagraphList::const_iterator pend = pars.end();
786                 for (; pit != pend; ++pit) {
787                         Paragraph par(*pit, 0, 26);
788                         // adapt paragraph to current buffer.
789                         par.setBuffer(const_cast<Buffer &>(*buf));
790                         asciiSel += par.asString(AS_STR_INSETS);
791                         if (asciiSel.size() > 25) {
792                                 asciiSel.replace(22, docstring::npos,
793                                                  from_ascii("..."));
794                                 break;
795                         }
796                 }
797
798                 selList.push_back(asciiSel);
799         }
800
801         return selList;
802 }
803
804
805 size_type numberOfSelections()
806 {
807         return theCuts.size();
808 }
809
810
811 void cutSelection(Cursor & cur, bool doclear, bool realcut)
812 {
813         // This doesn't make sense, if there is no selection
814         if (!cur.selection())
815                 return;
816
817         // OK, we have a selection. This is always between cur.selBegin()
818         // and cur.selEnd()
819
820         if (cur.inTexted()) {
821                 Text * text = cur.text();
822                 LBUFERR(text);
823
824                 saveSelection(cur);
825
826                 // make sure that the depth behind the selection are restored, too
827                 cur.recordUndoSelection();
828                 pit_type begpit = cur.selBegin().pit();
829                 pit_type endpit = cur.selEnd().pit();
830
831                 int endpos = cur.selEnd().pos();
832
833                 BufferParams const & bp = cur.buffer()->params();
834                 if (realcut) {
835                         copySelectionHelper(*cur.buffer(),
836                                 *text,
837                                 begpit, endpit,
838                                 cur.selBegin().pos(), endpos,
839                                 bp.documentClassPtr(), theCuts);
840                         // Stuff what we got on the clipboard.
841                         // Even if there is no selection.
842                         putClipboard(theCuts[0].first, theCuts[0].second,
843                                 cur.selectionAsString(true));
844                 }
845
846                 if (begpit != endpit)
847                         cur.screenUpdateFlags(Update::Force | Update::FitCursor);
848
849                 boost::tie(endpit, endpos) =
850                         eraseSelectionHelper(bp,
851                                 text->paragraphs(),
852                                 begpit, endpit,
853                                 cur.selBegin().pos(), endpos);
854
855                 // cutSelection can invalidate the cursor so we need to set
856                 // it anew. (Lgb)
857                 // we prefer the end for when tracking changes
858                 cur.pos() = endpos;
859                 cur.pit() = endpit;
860
861                 // sometimes necessary
862                 if (doclear
863                         && text->paragraphs()[begpit].stripLeadingSpaces(bp.track_changes))
864                         cur.fixIfBroken();
865
866                 // need a valid cursor. (Lgb)
867                 cur.clearSelection();
868
869                 // After a cut operation, we must make sure that the Buffer is updated
870                 // because some further operation might need updated label information for
871                 // example. So we cannot just use "cur.forceBufferUpdate()" here.
872                 // This fixes #7071.
873                 cur.buffer()->updateBuffer();
874
875                 // tell tabular that a recent copy happened
876                 dirtyTabularStack(false);
877         }
878
879         if (cur.inMathed()) {
880                 if (cur.selBegin().idx() != cur.selEnd().idx()) {
881                         // The current selection spans more than one cell.
882                         // Record all cells
883                         cur.recordUndoInset();
884                 } else {
885                         // Record only the current cell to avoid a jumping
886                         // cursor after undo
887                         cur.recordUndo();
888                 }
889                 if (realcut)
890                         copySelection(cur);
891                 eraseSelection(cur);
892         }
893 }
894
895
896 void copySelection(Cursor const & cur)
897 {
898         copySelection(cur, cur.selectionAsString(true));
899 }
900
901
902 void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext)
903 {
904         ParagraphList pars;
905         Paragraph par;
906         BufferParams const & bp = cur.buffer()->params();
907         par.setLayout(bp.documentClass().plainLayout());
908         Font font(inherit_font, bp.language);
909         par.insertInset(0, inset, font, Change(Change::UNCHANGED));
910         pars.push_back(par);
911         theCuts.push(make_pair(pars, bp.documentClassPtr()));
912
913         // stuff the selection onto the X clipboard, from an explicit copy request
914         putClipboard(theCuts[0].first, theCuts[0].second, plaintext);
915 }
916
917
918 namespace {
919
920 void copySelectionToStack(Cursor const & cur, CutStack & cutstack)
921 {
922         // this doesn't make sense, if there is no selection
923         if (!cur.selection())
924                 return;
925
926         // copySelection can not yet handle the case of cross idx selection
927         if (cur.selBegin().idx() != cur.selEnd().idx())
928                 return;
929
930         if (cur.inTexted()) {
931                 Text * text = cur.text();
932                 LBUFERR(text);
933                 // ok we have a selection. This is always between cur.selBegin()
934                 // and sel_end cursor
935
936                 // copy behind a space if there is one
937                 ParagraphList & pars = text->paragraphs();
938                 pos_type pos = cur.selBegin().pos();
939                 pit_type par = cur.selBegin().pit();
940                 while (pos < pars[par].size() &&
941                        pars[par].isLineSeparator(pos) &&
942                        (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
943                         ++pos;
944
945                 copySelectionHelper(*cur.buffer(), *text, par, cur.selEnd().pit(),
946                         pos, cur.selEnd().pos(), 
947                         cur.buffer()->params().documentClassPtr(), cutstack);
948
949                 // Reset the dirty_tabular_stack_ flag only when something
950                 // is copied to the clipboard (not to the selectionBuffer).
951                 if (&cutstack == &theCuts)
952                         dirtyTabularStack(false);
953         }
954
955         if (cur.inMathed()) {
956                 //lyxerr << "copySelection in mathed" << endl;
957                 ParagraphList pars;
958                 Paragraph par;
959                 BufferParams const & bp = cur.buffer()->params();
960                 // FIXME This should be the plain layout...right?
961                 par.setLayout(bp.documentClass().plainLayout());
962                 par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED));
963                 pars.push_back(par);
964                 cutstack.push(make_pair(pars, bp.documentClassPtr()));
965         }
966 }
967
968 }
969
970
971 void copySelectionToStack()
972 {
973         if (!selectionBuffer.empty())
974                 theCuts.push(selectionBuffer[0]);
975 }
976
977
978 void copySelection(Cursor const & cur, docstring const & plaintext)
979 {
980         // In tablemode, because copy and paste actually use special table stack
981         // we do not attempt to get selected paragraphs under cursor. Instead, a
982         // paragraph with the plain text version is generated so that table cells
983         // can be pasted as pure text somewhere else.
984         if (cur.selBegin().idx() != cur.selEnd().idx()) {
985                 ParagraphList pars;
986                 Paragraph par;
987                 BufferParams const & bp = cur.buffer()->params();
988                 par.setLayout(bp.documentClass().plainLayout());
989                 par.insert(0, plaintext, Font(), Change(Change::UNCHANGED));
990                 pars.push_back(par);
991                 theCuts.push(make_pair(pars, bp.documentClassPtr()));
992         } else {
993                 copySelectionToStack(cur, theCuts);
994         }
995
996         // stuff the selection onto the X clipboard, from an explicit copy request
997         putClipboard(theCuts[0].first, theCuts[0].second, plaintext);
998 }
999
1000
1001 void saveSelection(Cursor const & cur)
1002 {
1003         // This function is called, not when a selection is formed, but when
1004         // a selection is cleared. Therefore, multiple keyboard selection
1005         // will not repeatively trigger this function (bug 3877).
1006         if (cur.selection() 
1007             && cur.selBegin() == cur.bv().cursor().selBegin()
1008             && cur.selEnd() == cur.bv().cursor().selEnd()) {
1009                 LYXERR(Debug::SELECTION, "saveSelection: '" << cur.selectionAsString(true) << "'");
1010                 copySelectionToStack(cur, selectionBuffer);
1011         }
1012 }
1013
1014
1015 bool selection()
1016 {
1017         return !selectionBuffer.empty();
1018 }
1019
1020
1021 void clearSelection()
1022 {
1023         selectionBuffer.clear();
1024 }
1025
1026
1027 void clearCutStack()
1028 {
1029         theCuts.clear();
1030 }
1031
1032
1033 docstring selection(size_t sel_index)
1034 {
1035         return sel_index < theCuts.size()
1036                 ? theCuts[sel_index].first.back().asString(AS_STR_INSETS | AS_STR_NEWLINES)
1037                 : docstring();
1038 }
1039
1040
1041 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
1042                         DocumentClassConstPtr docclass, ErrorList & errorList)
1043 {
1044         if (cur.inTexted()) {
1045                 Text * text = cur.text();
1046                 LBUFERR(text);
1047
1048                 PasteReturnValue prv =
1049                         pasteSelectionHelper(cur, parlist, docclass, 0, errorList);
1050                 cur.forceBufferUpdate();
1051                 cur.clearSelection();
1052                 text->setCursor(cur, prv.par, prv.pos);
1053         }
1054
1055         // mathed is handled in InsetMathNest/InsetMathGrid
1056         LATTEST(!cur.inMathed());
1057 }
1058
1059
1060 bool pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index)
1061 {
1062         // this does not make sense, if there is nothing to paste
1063         if (!checkPastePossible(sel_index))
1064                 return false;
1065
1066         cur.recordUndo();
1067         pasteParagraphList(cur, theCuts[sel_index].first,
1068                            theCuts[sel_index].second, errorList);
1069         return true;
1070 }
1071
1072
1073 bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
1074                         Clipboard::TextType type)
1075 {
1076         // Use internal clipboard if it is the most recent one
1077         // This overrides asParagraphs and type on purpose!
1078         if (theClipboard().isInternal())
1079                 return pasteFromStack(cur, errorList, 0);
1080
1081         // First try LyX format
1082         if ((type == Clipboard::LyXTextType ||
1083              type == Clipboard::LyXOrPlainTextType ||
1084              type == Clipboard::AnyTextType) &&
1085             theClipboard().hasTextContents(Clipboard::LyXTextType)) {
1086                 string lyx = theClipboard().getAsLyX();
1087                 if (!lyx.empty()) {
1088                         // For some strange reason gcc 3.2 and 3.3 do not accept
1089                         // Buffer buffer(string(), false);
1090                         Buffer buffer("", false);
1091                         buffer.setUnnamed(true);
1092                         if (buffer.readString(lyx)) {
1093                                 cur.recordUndo();
1094                                 pasteParagraphList(cur, buffer.paragraphs(),
1095                                         buffer.params().documentClassPtr(), errorList);
1096                                 return true;
1097                         }
1098                 }
1099         }
1100
1101         // Then try TeX and HTML
1102         Clipboard::TextType types[2] = {Clipboard::HtmlTextType, Clipboard::LaTeXTextType};
1103         string names[2] = {"html", "latexclipboard"};
1104         for (int i = 0; i < 2; ++i) {
1105                 if (type != types[i] && type != Clipboard::AnyTextType)
1106                         continue;
1107                 bool available = theClipboard().hasTextContents(types[i]);
1108
1109                 // If a specific type was explicitly requested, try to
1110                 // interpret plain text: The user told us that the clipboard
1111                 // contents is in the desired format
1112                 if (!available && type == types[i]) {
1113                         types[i] = Clipboard::PlainTextType;
1114                         available = theClipboard().hasTextContents(types[i]);
1115                 }
1116
1117                 if (available) {
1118                         docstring text = theClipboard().getAsText(types[i]);
1119                         available = !text.empty();
1120                         if (available) {
1121                                 // For some strange reason gcc 3.2 and 3.3 do not accept
1122                                 // Buffer buffer(string(), false);
1123                                 Buffer buffer("", false);
1124                                 buffer.setUnnamed(true);
1125                                 available = buffer.importString(names[i], text, errorList);
1126                                 if (available)
1127                                         available = !buffer.paragraphs().empty();
1128                                 if (available && !buffer.paragraphs()[0].empty()) {
1129                                         cur.recordUndo();
1130                                         pasteParagraphList(cur, buffer.paragraphs(),
1131                                                 buffer.params().documentClassPtr(), errorList);
1132                                         return true;
1133                                 }
1134                         }
1135                 }
1136         }
1137
1138         // Then try plain text
1139         docstring const text = theClipboard().getAsText(Clipboard::PlainTextType);
1140         if (text.empty())
1141                 return false;
1142         cur.recordUndo();
1143         if (asParagraphs)
1144                 cur.text()->insertStringAsParagraphs(cur, text, cur.current_font);
1145         else
1146                 cur.text()->insertStringAsLines(cur, text, cur.current_font);
1147         return true;
1148 }
1149
1150
1151 void pasteSimpleText(Cursor & cur, bool asParagraphs)
1152 {
1153         docstring text;
1154         // Use internal clipboard if it is the most recent one
1155         if (theClipboard().isInternal()) {
1156                 if (!checkPastePossible(0))
1157                         return;
1158
1159                 ParagraphList const & pars = theCuts[0].first;
1160                 ParagraphList::const_iterator it = pars.begin();
1161                 for (; it != pars.end(); ++it) {
1162                         if (it != pars.begin())
1163                                 text += "\n";
1164                         text += (*it).asString();
1165                 }
1166                 asParagraphs = false;
1167         } else {
1168                 // Then try plain text
1169                 text = theClipboard().getAsText(Clipboard::PlainTextType);
1170         }
1171
1172         if (text.empty())
1173                 return;
1174
1175         cur.recordUndo();
1176         cutSelection(cur, true, false);
1177         if (asParagraphs)
1178                 cur.text()->insertStringAsParagraphs(cur, text, cur.current_font);
1179         else
1180                 cur.text()->insertStringAsLines(cur, text, cur.current_font);
1181 }
1182
1183
1184 void pasteClipboardGraphics(Cursor & cur, ErrorList & /* errorList */,
1185                             Clipboard::GraphicsType preferedType)
1186 {
1187         LASSERT(theClipboard().hasGraphicsContents(preferedType), return);
1188
1189         // get picture from clipboard
1190         FileName filename = theClipboard().getAsGraphics(cur, preferedType);
1191         if (filename.empty())
1192                 return;
1193
1194         // create inset for graphic
1195         InsetGraphics * inset = new InsetGraphics(cur.buffer());
1196         InsetGraphicsParams params;
1197         params.filename = support::DocFileName(filename.absFileName(), false);
1198         inset->setParams(params);
1199         cur.recordUndo();
1200         cur.insert(inset);
1201 }
1202
1203
1204 void pasteSelection(Cursor & cur, ErrorList & errorList)
1205 {
1206         if (selectionBuffer.empty())
1207                 return;
1208         cur.recordUndo();
1209         pasteParagraphList(cur, selectionBuffer[0].first,
1210                            selectionBuffer[0].second, errorList);
1211 }
1212
1213
1214 void replaceSelectionWithString(Cursor & cur, docstring const & str)
1215 {
1216         cur.recordUndo();
1217         DocIterator selbeg = cur.selectionBegin();
1218
1219         // Get font setting before we cut, we need a copy here, not a bare reference.
1220         Font const font =
1221                 selbeg.paragraph().getFontSettings(cur.buffer()->params(), selbeg.pos());
1222
1223         // Insert the new string
1224         pos_type pos = cur.selEnd().pos();
1225         Paragraph & par = cur.selEnd().paragraph();
1226         docstring::const_iterator cit = str.begin();
1227         docstring::const_iterator end = str.end();
1228         for (; cit != end; ++cit, ++pos)
1229                 par.insertChar(pos, *cit, font, cur.buffer()->params().track_changes);
1230
1231         // Cut the selection
1232         cutSelection(cur, true, false);
1233 }
1234
1235
1236 void replaceSelection(Cursor & cur)
1237 {
1238         if (cur.selection())
1239                 cutSelection(cur, true, false);
1240 }
1241
1242
1243 void eraseSelection(Cursor & cur)
1244 {
1245         //lyxerr << "cap::eraseSelection begin: " << cur << endl;
1246         CursorSlice const & i1 = cur.selBegin();
1247         CursorSlice const & i2 = cur.selEnd();
1248         if (i1.inset().asInsetMath()) {
1249                 saveSelection(cur);
1250                 cur.top() = i1;
1251                 if (i1.idx() == i2.idx()) {
1252                         i1.cell().erase(i1.pos(), i2.pos());
1253                         // We may have deleted i1.cell(cur.pos()).
1254                         // Make sure that pos is valid.
1255                         if (cur.pos() > cur.lastpos())
1256                                 cur.pos() = cur.lastpos();
1257                 } else {
1258                         InsetMath * p = i1.asInsetMath();
1259                         Inset::row_type r1, r2;
1260                         Inset::col_type c1, c2;
1261                         region(i1, i2, r1, r2, c1, c2);
1262                         for (Inset::row_type row = r1; row <= r2; ++row)
1263                                 for (Inset::col_type col = c1; col <= c2; ++col)
1264                                         p->cell(p->index(row, col)).clear();
1265                         // We've deleted the whole cell. Only pos 0 is valid.
1266                         cur.pos() = 0;
1267                 }
1268                 // need a valid cursor. (Lgb)
1269                 cur.clearSelection();
1270         } else {
1271                 lyxerr << "can't erase this selection 1" << endl;
1272         }
1273         //lyxerr << "cap::eraseSelection end: " << cur << endl;
1274 }
1275
1276
1277 void selDel(Cursor & cur)
1278 {
1279         //lyxerr << "cap::selDel" << endl;
1280         if (cur.selection())
1281                 eraseSelection(cur);
1282 }
1283
1284
1285 void selClearOrDel(Cursor & cur)
1286 {
1287         //lyxerr << "cap::selClearOrDel" << endl;
1288         if (lyxrc.auto_region_delete)
1289                 selDel(cur);
1290         else
1291                 cur.setSelection(false);
1292 }
1293
1294
1295 docstring grabSelection(Cursor const & cur)
1296 {
1297         if (!cur.selection())
1298                 return docstring();
1299
1300 #if 0
1301         // grab selection by glueing multiple cells together. This is not what
1302         // we want because selections spanning multiple cells will get "&" and "\\"
1303         // seperators.
1304         ostringstream os;
1305         for (DocIterator dit = cur.selectionBegin();
1306              dit != cur.selectionEnd(); dit.forwardPos())
1307                 os << asString(dit.cell());
1308         return os.str();
1309 #endif
1310
1311         CursorSlice i1 = cur.selBegin();
1312         CursorSlice i2 = cur.selEnd();
1313
1314         if (i1.idx() == i2.idx()) {
1315                 if (i1.inset().asInsetMath()) {
1316                         MathData::const_iterator it = i1.cell().begin();
1317                         Buffer * buf = cur.buffer();
1318                         return asString(MathData(buf, it + i1.pos(), it + i2.pos()));
1319                 } else {
1320                         return from_ascii("unknown selection 1");
1321                 }
1322         }
1323
1324         Inset::row_type r1, r2;
1325         Inset::col_type c1, c2;
1326         region(i1, i2, r1, r2, c1, c2);
1327
1328         docstring data;
1329         if (i1.inset().asInsetMath()) {
1330                 for (Inset::row_type row = r1; row <= r2; ++row) {
1331                         if (row > r1)
1332                                 data += "\\\\";
1333                         for (Inset::col_type col = c1; col <= c2; ++col) {
1334                                 if (col > c1)
1335                                         data += '&';
1336                                 data += asString(i1.asInsetMath()->
1337                                         cell(i1.asInsetMath()->index(row, col)));
1338                         }
1339                 }
1340         } else {
1341                 data = from_ascii("unknown selection 2");
1342         }
1343         return data;
1344 }
1345
1346
1347 void dirtyTabularStack(bool b)
1348 {
1349         dirty_tabular_stack_ = b;
1350 }
1351
1352
1353 bool tabularStackDirty()
1354 {
1355         return dirty_tabular_stack_;
1356 }
1357
1358
1359 } // namespace cap
1360 } // namespace lyx