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