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