]> git.lyx.org Git - lyx.git/blob - src/CutAndPaste.h
Make insertInset use a temporary cut-and-paste area.
[lyx.git] / src / CutAndPaste.h
1 // -*- C++ -*-
2 /**
3  * \file CutAndPaste.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  * \author Alfredo Braunstein
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef CUTANDPASTE_H
15 #define CUTANDPASTE_H
16
17 #include "DocumentClassPtr.h"
18
19 #include "support/docstring.h"
20
21 #include "frontends/Clipboard.h"
22
23 #include <vector>
24
25
26 namespace lyx {
27
28 class DocumentClass;
29 class ErrorList;
30 class InsetText;
31 class Cursor;
32 class ParagraphList;
33
34 namespace cap {
35
36 /// Get all elements of the cut buffer in plain text format.
37 std::vector<docstring> availableSelections(Buffer const *);
38 /// Get the number of available elements in the cut buffer.
39 size_type numberOfSelections();
40 /// Get the sel_index-th element of the cut buffer in plain text format.
41 docstring selection(size_t sel_index, DocumentClassConstPtr docclass);
42
43 /**
44  * Replace using the font of the first selected character and select
45  * the new string. Does handle undo.
46  */
47 void replaceSelectionWithString(Cursor & cur, docstring const & str);
48 /// If a selection exists, delete it without pushing it to the cut buffer.
49 /// Does handle undo.
50 void replaceSelection(Cursor & cur);
51
52 /**
53  * Cut the current selection and possibly push it to the cut buffer and
54  * system clipboard.
55  * Does handle undo. Calls saveSelection.
56  * \param doclear If this is true: Delete leading spaces in paragraphs before
57  *                they get merged.
58  * \param realcut If this is true: Push the selection to the cut buffer and
59  *                system clipboard. Set this to false to only delete the
60  *                selection.
61  */
62 void cutSelection(Cursor & cur, bool doclear = true, bool realcut = true);
63 /// Like cutSelection, but only put to temporary cut buffer
64 void cutSelectionToTemp(Cursor & cur, bool doclear = true, bool realcut = true);
65
66 /// Push the current selection to the cut buffer and the system clipboard.
67 void copySelection(Cursor const & cur);
68 ///
69 void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext);
70 /**
71  * Push the current selection to the cut buffer and the system clipboard.
72  * \param plaintext plain text version of the selection for the system
73  *        clipboard
74  */
75 void copySelection(Cursor const & cur, docstring const & plaintext);
76 /// Push the selection buffer to the cut buffer.
77 void copySelectionToStack();
78 /// Store the current selection in the internal selection buffer
79 void saveSelection(Cursor const & cur);
80 /// Is a selection available in our selection buffer?
81 bool selection();
82 /// Clear our selection buffer
83 void clearSelection();
84 /// Clear our cut stack.
85 void clearCutStack();
86 /// Paste the current selection at \p cur
87 /// Does handle undo. Does only work in text, not mathed.
88 void pasteSelection(Cursor & cur, ErrorList &);
89 /// Replace the current selection with the clipboard contents as text
90 /// (internal or external: which is newer).
91 /// Does handle undo. Does only work in text, not mathed.
92 /// \p asParagraphs is only considered if plain text is pasted.
93 bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
94         frontend::Clipboard::TextType preferedType = frontend::Clipboard::LyXOrPlainTextType);
95 /// Replace the current selection with the clipboard contents as graphic.
96 /// Does handle undo. Does only work in text, not mathed.
97 void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
98         frontend::Clipboard::GraphicsType preferedType = frontend::Clipboard::AnyGraphicsType);
99 /// Replace the current selection with cut buffer \c sel_index
100 /// Does handle undo. Does only work in text, not mathed.
101 bool pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
102 /// Replace the current selection with temporary cut buffer
103 /// Does handle undo. Does only work in text, not mathed.
104 bool pasteFromTemp(Cursor & cur, ErrorList & errorList);
105 /// Paste the clipboard as simple text, removing any formatting
106 void pasteSimpleText(Cursor & cur, bool asParagraphs);
107
108 // What to do with unknown branches?
109 enum BranchAction {
110         BRANCH_ADD, // add the branch unconditionally
111         BRANCH_IGNORE, // leave the branch undefined
112         BRANCH_ASK // ask the user whether the branch should be added
113 };
114 /// Paste the paragraph list \p parlist at the position given by \p cur.
115 /// Does not handle undo. Does only work in text, not mathed.
116 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
117                         DocumentClassConstPtr textclass, ErrorList & errorList,
118                         BranchAction branchAction = BRANCH_ASK);
119
120
121 /** Needed to switch between different classes. This works
122  *  for a list of paragraphs beginning with the specified par.
123  *  It changes layouts and character styles.
124  */
125 void switchBetweenClasses(DocumentClassConstPtr c1,
126                         DocumentClassConstPtr c2, InsetText & in, ErrorList &);
127
128 /// Get the current selection as a string. Does not change the selection.
129 /// Does only work if the whole selection is in mathed.
130 docstring grabSelection(Cursor const & cur);
131 /// Erase the current selection.
132 /// Does not handle undo. Does only work if the whole selection is in mathed.
133 /// Calls saveSelection.
134 void eraseSelection(Cursor & cur);
135 /// Reduce the selected text in mathed to only one cell. If it spans multiple
136 /// cells, the cursor is moved the end of the current cell and the anchor to the
137 /// start. If the selection is inside only one cell, nothing is done. Return
138 /// true if the selection now does not span multiple cells anymore.
139 bool reduceSelectionToOneCell(Cursor & cur);
140 /// Returns true if multiple cells are selected in mathed.
141 bool multipleCellsSelected(Cursor const & cur);
142 /// Erase the selection and return it as a string.
143 /// Does not handle undo. Does only work if the whole selection is in mathed.
144 docstring grabAndEraseSelection(Cursor & cur);
145 // other selection methods
146 /// Erase the selection if one exists.
147 /// Does not handle undo. Does only work if the whole selection is in mathed.
148 void selDel(Cursor & cur);
149 /// Clear or delete the selection if one exists, depending on lyxrc setting.
150 /// Does not handle undo. Does only work if the whole selection is in mathed.
151 void selClearOrDel(Cursor & cur);
152 /// Calculate rectangular region of cell between \c i1 and \c i2.
153 void region(CursorSlice const & i1, CursorSlice const & i2,
154     Inset::row_type & r1, Inset::row_type & r2,
155     Inset::col_type & c1, Inset::col_type & c2);
156 /** Tabular has its own paste stack for multiple cells
157  *  but it needs to know whether there is a more recent
158  *  ordinary paste. Therefore which one is newer.
159  */
160 //FIXME: this is a workaround for bug 1919. Replace this by
161 //an all-for-one-paste mechanism in 1.7
162 /// store whether tabular or ordinary paste stack is newer
163 void dirtyTabularStack(bool b);
164 /// is the tabular paste stack newer than the ordinary one?
165 bool tabularStackDirty();
166 } // namespace cap
167 } // namespce lyx
168
169 #endif