]> git.lyx.org Git - lyx.git/blob - src/CutAndPaste.C
Georg Baum's and my math array partition lines related stuff
[lyx.git] / src / CutAndPaste.C
1 /*
2  * \file CutAndPaste.C
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  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "CutAndPaste.h"
16
17 #include "buffer.h"
18 #include "buffer_funcs.h"
19 #include "bufferparams.h"
20 #include "BufferView.h"
21 #include "cursor.h"
22 #include "debug.h"
23 #include "errorlist.h"
24 #include "funcrequest.h"
25 #include "gettext.h"
26 #include "lfuns.h"
27 #include "lyxrc.h"
28 #include "lyxtext.h"
29 #include "lyxtextclasslist.h"
30 #include "paragraph.h"
31 #include "paragraph_funcs.h"
32 #include "ParagraphParameters.h"
33 #include "ParagraphList_fwd.h"
34 #include "pariterator.h"
35 #include "undo.h"
36
37 #include "insets/insettabular.h"
38
39 #include "mathed/math_data.h"
40 #include "mathed/math_inset.h"
41 #include "mathed/math_support.h"
42
43 #include "support/lstrings.h"
44
45 #include <boost/tuple/tuple.hpp>
46
47 using lyx::pos_type;
48 using lyx::pit_type;
49 using lyx::textclass_type;
50
51 using lyx::support::bformat;
52
53 using std::endl;
54 using std::for_each;
55 using std::make_pair;
56 using std::pair;
57 using std::vector;
58 using std::string;
59
60
61 namespace {
62
63 typedef std::pair<lyx::pit_type, int> PitPosPair;
64
65 typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
66
67 CutStack theCuts(10);
68
69 class resetOwnerAndChanges : public std::unary_function<Paragraph, void> {
70 public:
71         void operator()(Paragraph & p) const {
72                 p.cleanChanges();
73                 p.setInsetOwner(0);
74         }
75 };
76
77
78 void region(CursorSlice const & i1, CursorSlice const & i2,
79         InsetBase::row_type & r1, InsetBase::row_type & r2,
80         InsetBase::col_type & c1, InsetBase::col_type & c2)
81 {
82         InsetBase & p = i1.inset();
83         c1 = p.col(i1.idx());
84         c2 = p.col(i2.idx());
85         if (c1 > c2)
86                 std::swap(c1, c2);
87         r1 = p.row(i1.idx());
88         r2 = p.row(i2.idx());
89         if (r1 > r2)
90                 std::swap(r1, r2);
91 }
92
93
94 bool checkPastePossible(int index)
95 {
96         return size_t(index) < theCuts.size() && !theCuts[index].first.empty();
97 }
98
99
100 pair<PitPosPair, pit_type>
101 pasteSelectionHelper(Buffer const & buffer, ParagraphList & pars,
102         pit_type pit, int pos,
103         textclass_type tc, size_t cut_index, ErrorList & errorlist)
104 {
105         if (!checkPastePossible(cut_index))
106                 return make_pair(PitPosPair(pit, pos), pit);
107
108         BOOST_ASSERT (pos <= pars[pit].size());
109
110         // Make a copy of the CaP paragraphs.
111         ParagraphList insertion = theCuts[cut_index].first;
112         textclass_type const textclass = theCuts[cut_index].second;
113
114         // Now remove all out of the pars which is NOT allowed in the
115         // new environment and set also another font if that is required.
116
117         // Convert newline to paragraph break in ERT inset.
118         // This should not be here!
119         if (pars[pit].inInset() &&
120             pars[pit].inInset()->lyxCode() == InsetBase::ERT_CODE) {
121                 for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) {
122                         for (pos_type j = 0; j < insertion[i].size(); ++j) {
123                                 if (insertion[i].isNewline(j)) {
124                                         insertion[i].erase(j);
125                                         breakParagraphConservative(
126                                                         buffer.params(),
127                                                         insertion, i, j);
128                                 }
129                         }
130                 }
131         }
132
133         // Make sure there is no class difference.
134         lyx::cap::SwitchLayoutsBetweenClasses(textclass, tc, insertion,
135                                     errorlist);
136
137         ParagraphList::iterator tmpbuf = insertion.begin();
138         int depth_delta = pars[pit].params().depth() - tmpbuf->params().depth();
139
140         Paragraph::depth_type max_depth = pars[pit].getMaxDepthAfter();
141
142         for (; tmpbuf != insertion.end(); ++tmpbuf) {
143                 // If we have a negative jump so that the depth would
144                 // go below 0 depth then we have to redo the delta to
145                 // this new max depth level so that subsequent
146                 // paragraphs are aligned correctly to this paragraph
147                 // at level 0.
148                 if (int(tmpbuf->params().depth()) + depth_delta < 0)
149                         depth_delta = 0;
150
151                 // Set the right depth so that we are not too deep or shallow.
152                 tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
153                 if (tmpbuf->params().depth() > max_depth)
154                         tmpbuf->params().depth(max_depth);
155
156                 // Only set this from the 2nd on as the 2nd depends
157                 // for maxDepth still on pit.
158                 if (tmpbuf != insertion.begin())
159                         max_depth = tmpbuf->getMaxDepthAfter();
160
161                 // Set the inset owner of this paragraph.
162                 tmpbuf->setInsetOwner(pars[pit].inInset());
163                 for (pos_type i = 0; i < tmpbuf->size(); ++i) {
164                         if (tmpbuf->getChar(i) == Paragraph::META_INSET &&
165                             !pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode()))
166                                 tmpbuf->erase(i--);
167                 }
168         }
169
170         bool const empty = pars[pit].empty();
171         if (!empty) {
172                 // Make the buf exactly the same layout as the cursor
173                 // paragraph.
174                 insertion.begin()->makeSameLayout(pars[pit]);
175         }
176
177         // Prepare the paragraphs and insets for insertion.
178         // A couple of insets store buffer references so need updating.
179         InsetText in;
180         std::swap(in.paragraphs(), insertion);
181
182         ParIterator fpit = par_iterator_begin(in);
183         ParIterator fend = par_iterator_end(in);
184
185         for (; fpit != fend; ++fpit) {
186                 InsetList::iterator lit = fpit->insetlist.begin();
187                 InsetList::iterator eit = fpit->insetlist.end();
188
189                 for (; lit != eit; ++lit) {
190                         switch (lit->inset->lyxCode()) {
191                         case InsetBase::TABULAR_CODE: {
192                                 InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
193                                 it->buffer(&buffer);
194                                 break;
195                         }
196
197                         default:
198                                 break; // nothing
199                         }
200                 }
201         }
202         std::swap(in.paragraphs(), insertion);
203
204         // Split the paragraph for inserting the buf if necessary.
205         if (!empty)
206                 breakParagraphConservative(buffer.params(), pars, pit, pos);
207
208         // Paste it!
209         if (empty) {
210                 pars.insert(pars.begin() + pit, insertion.begin(),
211                             insertion.end());
212
213                 // merge the empty par with the last par of the insertion
214                 mergeParagraph(buffer.params(), pars,
215                                pit + insertion.size() - 1);
216         } else {
217                 pars.insert(pars.begin() + pit + 1, insertion.begin(),
218                             insertion.end());
219
220                 // merge the first par of the insertion with the current par
221                 mergeParagraph(buffer.params(), pars, pit);
222         }
223
224         pit_type last_paste = pit + insertion.size() - 1;
225
226         // Store the new cursor position.
227         pit = last_paste;
228         pos = pars[last_paste].size();
229
230         // Maybe some pasting.
231         if (!empty && last_paste + 1 != pit_type(pars.size())) {
232                 if (pars[last_paste + 1].hasSameLayout(pars[last_paste])) {
233                         mergeParagraph(buffer.params(), pars, last_paste);
234                 } else if (pars[last_paste + 1].empty()) {
235                         pars[last_paste + 1].makeSameLayout(pars[last_paste]);
236                         mergeParagraph(buffer.params(), pars, last_paste);
237                 } else if (pars[last_paste].empty()) {
238                         pars[last_paste].makeSameLayout(pars[last_paste + 1]);
239                         mergeParagraph(buffer.params(), pars, last_paste);
240                 } else {
241                         pars[last_paste + 1].stripLeadingSpaces();
242                         ++last_paste;
243                 }
244         }
245
246         return make_pair(PitPosPair(pit, pos), last_paste + 1);
247 }
248
249
250 PitPosPair eraseSelectionHelper(BufferParams const & params,
251         ParagraphList & pars,
252         pit_type startpit, pit_type endpit,
253         int startpos, int endpos, bool doclear)
254 {
255         if (startpit == pit_type(pars.size()) ||
256             (startpos > pars[startpit].size()))
257                 return PitPosPair(endpit, endpos);
258
259         if (endpit == pit_type(pars.size()) ||
260             startpit == endpit) {
261                 endpos -= pars[startpit].erase(startpos, endpos);
262                 return PitPosPair(endpit, endpos);
263         }
264
265         // clear end/begin fragments of the first/last par in selection
266         bool all_erased = true;
267
268         pars[startpit].erase(startpos, pars[startpit].size());
269         if (pars[startpit].size() != startpos)
270                 all_erased = false;
271
272         endpos -= pars[endpit].erase(0, endpos);
273         if (endpos != 0)
274                 all_erased = false;
275
276         // Loop through the deleted pars if any, erasing as needed
277         for (pit_type pit = startpit + 1; pit != endpit;) {
278                 // "erase" the contents of the par
279                 pars[pit].erase(0, pars[pit].size());
280                 if (!pars[pit].size()) {
281                         // remove the par if it's now empty
282                         pars.erase(pars.begin() + pit);
283                         --endpit;
284                 } else {
285                         ++pit;
286                         all_erased = false;
287                 }
288         }
289
290 #if 0 // FIXME: why for cut but not copy ?
291         // the cut selection should begin with standard layout
292         if (realcut) {
293                 buf->params().clear();
294                 buf->bibkey = 0;
295                 buf->layout(textclasslist[buffer->params.textclass].defaultLayoutName());
296         }
297 #endif
298
299         if (startpit + 1 == pit_type(pars.size()))
300                 return PitPosPair(endpit, endpos);
301
302         if (doclear) {
303                 pars[startpit + 1].stripLeadingSpaces();
304         }
305
306         // paste the paragraphs again, if possible
307         if (all_erased &&
308             (pars[startpit].hasSameLayout(pars[startpit + 1]) ||
309              pars[startpit + 1].empty())) {
310                 mergeParagraph(params, pars, startpit);
311                 // this because endpar gets deleted here!
312                 endpit = startpit;
313                 endpos = startpos;
314         }
315
316         return PitPosPair(endpit, endpos);
317
318 }
319
320
321 void copySelectionHelper(ParagraphList & pars,
322         pit_type startpit, pit_type endpit,
323         int start, int end, textclass_type tc)
324 {
325         BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
326         BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
327         BOOST_ASSERT(startpit != endpit || start <= end);
328
329         // Clone the paragraphs within the selection.
330         ParagraphList paragraphs(pars.begin() + startpit, pars.begin() + endpit + 1);
331         for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges());
332
333         // Cut out the end of the last paragraph.
334         Paragraph & back = paragraphs.back();
335         back.erase(end, back.size());
336
337         // Cut out the begin of the first paragraph
338         Paragraph & front = paragraphs.front();
339         front.erase(0, start);
340
341         theCuts.push(make_pair(paragraphs, tc));
342 }
343
344
345
346 PitPosPair cutSelectionHelper(BufferParams const & params,
347         ParagraphList & pars, pit_type startpit, pit_type endpit,
348         int startpos, int endpos, textclass_type tc, bool doclear)
349 {
350         copySelectionHelper(pars, startpit, endpit, startpos, endpos, tc);
351         return eraseSelectionHelper(params, pars, startpit, endpit,
352                 startpos, endpos, doclear);
353 }
354
355
356 } // namespace anon
357
358
359
360
361 namespace lyx {
362 namespace cap {
363
364 string grabAndEraseSelection(LCursor & cur)
365 {
366         if (!cur.selection())
367                 return string();
368         string res = grabSelection(cur);
369         eraseSelection(cur);
370         cur.selection() = false;
371         return res;
372 }
373
374
375 int SwitchLayoutsBetweenClasses(textclass_type c1, textclass_type c2,
376         ParagraphList & pars, ErrorList & errorlist)
377 {
378         BOOST_ASSERT(!pars.empty());
379         int ret = 0;
380         if (c1 == c2)
381                 return ret;
382
383         LyXTextClass const & tclass1 = textclasslist[c1];
384         LyXTextClass const & tclass2 = textclasslist[c2];
385
386         InsetText in;
387         std::swap(in.paragraphs(), pars);
388
389         ParIterator end = par_iterator_end(in);
390         for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
391                 string const name = it->layout()->name();
392                 bool hasLayout = tclass2.hasLayout(name);
393
394                 if (hasLayout)
395                         it->layout(tclass2[name]);
396                 else
397                         it->layout(tclass2.defaultLayout());
398
399                 if (!hasLayout && name != tclass1.defaultLayoutName()) {
400                         ++ret;
401                         string const s = bformat(
402                                 _("Layout had to be changed from\n%1$s to %2$s\n"
403                                 "because of class conversion from\n%3$s to %4$s"),
404                          name, it->layout()->name(), tclass1.name(), tclass2.name());
405                         // To warn the user that something had to be done.
406                         errorlist.push_back(ErrorItem("Changed Layout", s,
407                                                       it->id(), 0,
408                                                       it->size()));
409                 }
410         }
411         std::swap(in.paragraphs(), pars);
412         return ret;
413 }
414
415
416 std::vector<string> const availableSelections(Buffer const & buffer)
417 {
418         vector<string> selList;
419
420         CutStack::const_iterator cit = theCuts.begin();
421         CutStack::const_iterator end = theCuts.end();
422         for (; cit != end; ++cit) {
423                 // we do not use cit-> here because gcc 2.9x does not
424                 // like it (JMarc)
425                 ParagraphList const & pars = (*cit).first;
426                 string asciiSel;
427                 ParagraphList::const_iterator pit = pars.begin();
428                 ParagraphList::const_iterator pend = pars.end();
429                 for (; pit != pend; ++pit) {
430                         asciiSel += pit->asString(buffer, false);
431                         if (asciiSel.size() > 25) {
432                                 asciiSel.replace(22, string::npos, "...");
433                                 break;
434                         }
435                 }
436
437                 selList.push_back(asciiSel);
438         }
439
440         return selList;
441 }
442
443
444 int nrOfParagraphs()
445 {
446         return theCuts.empty() ? 0 : theCuts[0].first.size();
447 }
448
449
450 void cutSelection(LCursor & cur, bool doclear, bool realcut)
451 {
452         if (cur.inTexted()) {
453                 LyXText * text = cur.text();
454                 BOOST_ASSERT(text);
455                 // Stuff what we got on the clipboard. Even if there is no selection.
456
457                 // There is a problem with having the stuffing here in that the
458                 // larger the selection the slower LyX will get. This can be
459                 // solved by running the line below only when the selection has
460                 // finished. The solution used currently just works, to make it
461                 // faster we need to be more clever and probably also have more
462                 // calls to stuffClipboard. (Lgb)
463                 cur.bv().stuffClipboard(cur.selectionAsString(true));
464
465                 // This doesn't make sense, if there is no selection
466                 if (!cur.selection())
467                         return;
468
469                 // OK, we have a selection. This is always between cur.selBegin()
470                 // and cur.selEnd()
471
472                 // make sure that the depth behind the selection are restored, too
473                 recordUndoSelection(cur);
474                 pit_type begpit = cur.selBegin().pit();
475                 pit_type endpit = cur.selEnd().pit();
476
477                 int endpos = cur.selEnd().pos();
478
479                 BufferParams const & bp = cur.buffer().params();
480                 if (realcut) {
481                         copySelectionHelper(text->paragraphs(),
482                                 begpit, endpit,
483                                 cur.selBegin().pos(), endpos,
484                                 bp.textclass);
485                 }
486
487                 boost::tie(endpit, endpos) =
488                         eraseSelectionHelper(bp,
489                                 text->paragraphs(),
490                                 begpit, endpit,
491                                 cur.selBegin().pos(), endpos,
492                                 doclear);
493
494                 // sometimes necessary
495                 if (doclear)
496                         text->paragraphs()[begpit].stripLeadingSpaces();
497
498                 // cutSelection can invalidate the cursor so we need to set
499                 // it anew. (Lgb)
500                 // we prefer the end for when tracking changes
501                 cur.pos() = endpos;
502                 cur.pit() = endpit;
503
504                 // need a valid cursor. (Lgb)
505                 cur.clearSelection();
506                 text->updateCounters();
507         }
508
509         if (cur.inMathed()) {
510                 lyxerr << "cutSelection in mathed" << endl;
511                 LCursor tmp = cur;
512                 copySelection(cur);
513                 cur.selection() = false;
514                 eraseSelection(tmp);
515         }
516 }
517
518
519 void copySelection(LCursor & cur)
520 {
521         // stuff the selection onto the X clipboard, from an explicit copy request
522         cur.bv().stuffClipboard(cur.selectionAsString(true));
523
524         // this doesn't make sense, if there is no selection
525         if (!cur.selection())
526                 return;
527
528         if (cur.inTexted()) {
529                 LyXText * text = cur.text();
530                 BOOST_ASSERT(text);
531                 // ok we have a selection. This is always between cur.selBegin()
532                 // and sel_end cursor
533
534                 // copy behind a space if there is one
535                 ParagraphList & pars = text->paragraphs();
536                 pos_type pos = cur.selBegin().pos();
537                 pit_type par = cur.selBegin().pit();
538                 while (pos < pars[par].size()
539                                          && pars[par].isLineSeparator(pos)
540                                          && (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
541                         ++pos;
542
543                 copySelectionHelper(pars, par, cur.selEnd().pit(),
544                         pos, cur.selEnd().pos(), cur.buffer().params().textclass);
545         }
546
547         if (cur.inMathed()) {
548                 lyxerr << "copySelection in mathed" << endl;
549                 ParagraphList pars;
550                 pars.push_back(Paragraph());
551                 BufferParams const & bp = cur.buffer().params();
552                 pars.back().layout(bp.getLyXTextClass().defaultLayout());
553                 for_each(pars.begin(), pars.end(), resetOwnerAndChanges());
554                 pars.back().insert(0, grabSelection(cur), LyXFont());
555                 theCuts.push(make_pair(pars, bp.textclass));
556         }
557 }
558
559
560 std::string getSelection(Buffer const & buf, size_t sel_index)
561 {
562         return sel_index < theCuts.size()
563                 ? theCuts[sel_index].first.back().asString(buf, false)
564                 : string();
565 }
566
567
568 void pasteSelection(LCursor & cur, size_t sel_index)
569 {
570         // this does not make sense, if there is nothing to paste
571         lyxerr << "#### pasteSelection " << sel_index << endl;
572         if (!checkPastePossible(sel_index))
573                 return;
574
575         if (cur.inTexted()) {
576                 LyXText * text = cur.text();
577                 BOOST_ASSERT(text);
578
579                 recordUndo(cur);
580
581                 pit_type endpit;
582                 PitPosPair ppp;
583
584                 ErrorList el;
585
586                 boost::tie(ppp, endpit) =
587                         pasteSelectionHelper(cur.buffer(),
588                                                                 text->paragraphs(),
589                                                                 cur.pit(), cur.pos(),
590                                                                 cur.buffer().params().textclass,
591                                                                 sel_index, el);
592                 bufferErrors(cur.buffer(), el);
593                 cur.bv().showErrorList(_("Paste"));
594
595                 cur.clearSelection();
596                 cur.resetAnchor();
597                 text->setCursor(cur, ppp.first, ppp.second);
598                 cur.setSelection();
599                 text->updateCounters();
600         }
601
602         if (cur.inMathed()) {
603                 lyxerr << "### should be handled in MathNest/GridInset" << endl;
604         }
605 }
606
607
608 void setSelectionRange(LCursor & cur, pos_type length)
609 {
610         LyXText * text = cur.text();
611         BOOST_ASSERT(text);
612         if (!length)
613                 return;
614         cur.resetAnchor();
615         while (length--)
616                 text->cursorRight(cur);
617         cur.setSelection();
618 }
619
620
621 // simple replacing. The font of the first selected character is used
622 void replaceSelectionWithString(LCursor & cur, string const & str)
623 {
624         LyXText * text = cur.text();
625         BOOST_ASSERT(text);
626         recordUndo(cur);
627
628         // Get font setting before we cut
629         pos_type pos = cur.selEnd().pos();
630         Paragraph & par = text->getPar(cur.selEnd().pit());
631         LyXFont const font =
632                 par.getFontSettings(cur.buffer().params(), cur.selBegin().pos());
633
634         // Insert the new string
635         string::const_iterator cit = str.begin();
636         string::const_iterator end = str.end();
637         for (; cit != end; ++cit, ++pos)
638                 par.insertChar(pos, (*cit), font);
639
640         // Cut the selection
641         cutSelection(cur, true, false);
642 }
643
644
645 void replaceSelection(LCursor & cur)
646 {
647         if (cur.selection())
648                 cutSelection(cur, true, false);
649 }
650
651
652 // only used by the spellchecker
653 void replaceWord(LCursor & cur, string const & replacestring)
654 {
655         LyXText * text = cur.text();
656         BOOST_ASSERT(text);
657
658         replaceSelectionWithString(cur, replacestring);
659         setSelectionRange(cur, replacestring.length());
660
661         // Go back so that replacement string is also spellchecked
662         for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
663                 text->cursorLeft(cur);
664 }
665
666
667 void eraseSelection(LCursor & cur)
668 {
669         //lyxerr << "LCursor::eraseSelection begin: " << cur << endl;
670         CursorSlice const & i1 = cur.selBegin();
671         CursorSlice const & i2 = cur.selEnd();
672         if (i1.inset().asMathInset()) {
673                 if (i1.idx() == i2.idx()) {
674                         i1.cell().erase(i1.pos(), i2.pos());
675                 } else {
676                         MathInset * p = i1.asMathInset();
677                         InsetBase::row_type r1, r2;
678                         InsetBase::col_type c1, c2;
679                         region(i1, i2, r1, r2, c1, c2);
680                         for (InsetBase::row_type row = r1; row <= r2; ++row)
681                                 for (InsetBase::col_type col = c1; col <= c2; ++col)
682                                         p->cell(p->index(row, col)).clear();
683                 }
684                 cur.top() = i1;
685                 cur.pos() = 0; // We've deleted the whole cell. Only pos 0 is valid.
686                 cur.resetAnchor();
687         } else {
688                 lyxerr << "can't erase this selection 1" << endl;
689         }
690         //lyxerr << "LCursor::eraseSelection end: " << cur << endl;
691 }
692
693
694 void selDel(LCursor & cur)
695 {
696         //lyxerr << "LCursor::selDel" << endl;
697         if (cur.selection()) {
698                 eraseSelection(cur);
699                 cur.selection() = false;
700         }
701 }
702
703
704 void selClearOrDel(LCursor & cur)
705 {
706         //lyxerr << "LCursor::selClearOrDel" << endl;
707         if (lyxrc.auto_region_delete)
708                 selDel(cur);
709         else
710                 cur.selection() = false;
711 }
712
713
714 string grabSelection(LCursor & cur)
715 {
716         if (!cur.selection())
717                 return string();
718
719         CursorSlice i1 = cur.selBegin();
720         CursorSlice i2 = cur.selEnd();
721
722         if (i1.idx() == i2.idx()) {
723                 if (i1.inset().asMathInset()) {
724                         MathArray::const_iterator it = i1.cell().begin();
725                         return asString(MathArray(it + i1.pos(), it + i2.pos()));
726                 } else {
727                         return "unknown selection 1";
728                 }
729         }
730
731         InsetBase::row_type r1, r2;
732         InsetBase::col_type c1, c2;
733         region(i1, i2, r1, r2, c1, c2);
734
735         string data;
736         if (i1.inset().asMathInset()) {
737                 for (InsetBase::row_type row = r1; row <= r2; ++row) {
738                         if (row > r1)
739                                 data += "\\\\";
740                         for (InsetBase::col_type col = c1; col <= c2; ++col) {
741                                 if (col > c1)
742                                         data += '&';
743                                 data += asString(i1.asMathInset()->
744                                         cell(i1.asMathInset()->index(row, col)));
745                         }
746                 }
747         } else {
748                 data = "unknown selection 2";
749         }
750         return data;
751 }
752
753
754 } // namespace cap
755 } // namespace lyx